File tree Expand file tree Collapse file tree
main/java/de/peeeq/wurstscript/translation/imtranslation
test/java/tests/wurstscript/tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -198,7 +198,10 @@ public void visit(ImTupleSelection ts) {
198198 te .setParent (null );
199199 if (i != ti ) {
200200 // if not the thing we want to return, just keep it in statements for side-effects
201- extractSideEffect (te , stmts );
201+ ImExpr remaining = extractSideEffect (te , stmts );
202+ if (SideEffectAnalyzer .quickcheckHasSideeffects (remaining )) {
203+ stmts .add (remaining );
204+ }
202205 } else { // if it is the part we want to return ...
203206 result = extractSideEffect (te , stmts );
204207 }
Original file line number Diff line number Diff line change @@ -169,6 +169,28 @@ public void tupleReturningCallsAreCapturedBeforeComparison() throws IOException
169169 assertFalse (compiled .contains ("tupleEquals" ));
170170 }
171171
172+ @ Test
173+ public void selectingLaterTupleComponentStillInvokesProducer () throws IOException {
174+ test ().testLua (true ).executeProg ().lines (
175+ "package Test" ,
176+ "native testSuccess()" ,
177+ "tuple pair(int x, int y)" ,
178+ "class Producer" ,
179+ " int calls" ,
180+ " @noinline function produce(int seed) returns pair" ,
181+ " calls++" ,
182+ " return pair(seed, seed + calls)" ,
183+ "init" ,
184+ " let producer = new Producer()" ,
185+ " let selected = producer.produce(5).y" ,
186+ " if selected == 6 and producer.calls == 1" ,
187+ " testSuccess()"
188+ );
189+
190+ String compiled = compiledLua ("selectingLaterTupleComponentStillInvokesProducer" );
191+ assertFalse (compiled .contains ("tupleCopy" ));
192+ }
193+
172194 @ Test
173195 public void compiletimeGenericArrayReplayLeavesAreSplit () {
174196 String compiled = compileLuaWithRunArgs (
You can’t perform that action at this time.
0 commit comments