Skip to content

Commit 5afe445

Browse files
committed
Propagate closure types through statement blocks
1 parent dc1b299 commit 5afe445

3 files changed

Lines changed: 7 additions & 5 deletions

File tree

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/imtranslation/ClosureTranslator.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ private ImClass createClass() {
202202

203203

204204
ImExpr translated;
205-
boolean propagatesExpectedType = e.getImplementation() instanceof ExprIfElse
206-
|| e.getImplementation() instanceof ExprUnary;
205+
boolean propagatesExpectedType = ExprTranslation.isCompositeExpectedTypeExpression(e.getImplementation());
207206
if (propagatesExpectedType) {
208207
translated = ExprTranslation.translateWithExpectedType(
209208
e.getImplementation(), tr, impl, superMethod.attrReturnType());

de.peeeq.wurstscript/src/main/java/de/peeeq/wurstscript/translation/imtranslation/ExprTranslation.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ private static ImExprs translateExprs(List<Expr> arguments, ImTranslator t, ImFu
884884
return result;
885885
}
886886

887-
private static boolean isCompositeExpectedTypeExpression(Expr e) {
887+
static boolean isCompositeExpectedTypeExpression(Expr e) {
888888
return e instanceof ExprIfElse || e instanceof ExprUnary || e instanceof ExprStatementsBlock;
889889
}
890890

de.peeeq.wurstscript/src/test/java/tests/wurstscript/tests/LuaBackendAuditTests.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2358,6 +2358,9 @@ public void erasedGenericPrimitiveDefaultsPropagateThroughCompositeContexts() th
23582358
" let indexed = values[useBox ? box.get() : 0]",
23592359
" IntSupplier supplier = () -> (useBox ? box.get() : 0)",
23602360
" IntSupplier unarySupplier = () -> -box.get()",
2361+
" IntSupplier blockSupplier = () -> begin",
2362+
" return (useBox ? box.get() : 0)",
2363+
" end",
23612364
" let constructed = new Constructed(useBox ? box.get() : 0)",
23622365
" int blockValue = begin",
23632366
" return (useBox ? box.get() : 0)",
@@ -2368,12 +2371,12 @@ public void erasedGenericPrimitiveDefaultsPropagateThroughCompositeContexts() th
23682371
" switchValue = 0",
23692372
" if sum == 0 and builtinSum == 0 and overloaded == 0 and blockOverloaded == 0",
23702373
" and indexed == 7 and readArrayValue() == 7 and supplier.get() == 0",
2371-
" and unarySupplier.get() == 0",
2374+
" and unarySupplier.get() == 0 and blockSupplier.get() == 0",
23722375
" and blockValue == 0 and switchValue == 0 and constructed.get() == 0",
23732376
" testSuccess()"
23742377
);
23752378
String compiled = compiledLua("erasedGenericPrimitiveDefaultsPropagateThroughCompositeContexts");
2376-
assertEquals("each concrete integer consumer must normalize its erased generic input", 11,
2379+
assertEquals("each concrete integer consumer must normalize its erased generic input", 12,
23772380
countOccurrences(compiled, "__wurst_ensureInt(Box_Box_get("));
23782381
assertTrue("global primitive array reads must remain safe for foreign writes",
23792382
compiled.contains("__wurst_ensureInt(Test_values[0])"));

0 commit comments

Comments
 (0)