Skip to content

Commit 10e3bdf

Browse files
committed
Add coverage for set_tuple_element with OTP28
OTP28 compiler can generate a set_tuple_element opcode. Ensure test generates it and fix opcodesswitch conditional. Signed-off-by: Paul Guyot <[email protected]>
1 parent 90a5920 commit 10e3bdf

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/libAtomVM/opcodesswitch.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3426,7 +3426,6 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
34263426
break;
34273427
}
34283428

3429-
#if MINIMUM_OTP_COMPILER_VERSION <= 25
34303429
case OP_SET_TUPLE_ELEMENT: {
34313430
term new_element;
34323431
DECODE_COMPACT_TERM(new_element, pc);
@@ -3452,7 +3451,6 @@ HOT_FUNC int scheduler_entry_point(GlobalContext *glb)
34523451
#endif
34533452
break;
34543453
}
3455-
#endif
34563454

34573455
case OP_PUT_LIST: {
34583456

tests/erlang_tests/test_set_tuple_element.erl

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
-module(test_set_tuple_element).
2222

23-
-export([start/0, test/2]).
23+
-export([start/0, test/2, id/1]).
2424

2525
-record(big, {
2626
a = foo,
@@ -39,6 +39,7 @@ start() ->
3939
ok = test(thing1, {ha, ha}),
4040
ok = test(undefined, {ha, ha}),
4141
ok = test(undefined, {lets, try_this}),
42+
ok = test_set_tuple_element_op(),
4243
0.
4344

4445
test(G, J) ->
@@ -53,3 +54,15 @@ test(G, J) ->
5354

5455
make_a_change(Big, Thing1, Thing2) ->
5556
Big#big{g = Thing1, j = Thing2}.
57+
58+
id(X) -> X.
59+
60+
% This generates a set_tuple_element op with OTP28
61+
test_set_tuple_element_op() ->
62+
State0 = id({state, a, b, c, d, e, f, g}),
63+
State1 = setelement(6, State0, id([r1, r2])),
64+
State2 = setelement(8, State1, [r8, r9]),
65+
State3 = id(State2),
66+
[r8, r9] = element(8, State3),
67+
[r1, r2] = element(6, State3),
68+
ok.

0 commit comments

Comments
 (0)