Skip to content

Commit caf7a4e

Browse files
committed
Normalize erased generic range bounds
1 parent ea8b239 commit caf7a4e

2 files changed

Lines changed: 19 additions & 3 deletions

File tree

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

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import de.peeeq.wurstscript.types.TypesHelper;
1414
import de.peeeq.wurstscript.types.WurstType;
1515
import de.peeeq.wurstscript.types.WurstTypeArray;
16+
import de.peeeq.wurstscript.types.WurstTypeInt;
1617
import de.peeeq.wurstscript.types.WurstTypeVararg;
1718
import org.eclipse.jdt.annotation.Nullable;
1819

@@ -293,8 +294,8 @@ private static ImStmt case_StmtForRange(ImTranslator t, ImFunction f, LocalVarDe
293294
List<ImStmt> result = Lists.newArrayList();
294295
result.add(ImSet(loopVar, ImVarAccess(imLoopVar), fromExpr));
295296

296-
ImExpr toExpr = addCacheVariableSmart(t, f, result, to, TypesHelper.imInt());
297-
ImExpr stepExpr = addCacheVariableSmart(t, f, result, step, TypesHelper.imInt());
297+
ImExpr toExpr = addCacheVariableSmart(t, f, result, to, TypesHelper.imInt(), WurstTypeInt.instance());
298+
ImExpr stepExpr = addCacheVariableSmart(t, f, result, step, TypesHelper.imInt(), WurstTypeInt.instance());
298299

299300
ImStmts imBody = ImStmts();
300301
// exitwhen imLoopVar > toExpr
@@ -310,6 +311,18 @@ private static ImStmt case_StmtForRange(ImTranslator t, ImFunction f, LocalVarDe
310311

311312
private static ImExpr addCacheVariableSmart(ImTranslator t, ImFunction f, List<ImStmt> result, Expr toCache, ImType type) {
312313
ImExpr r = toCache.imTranslateExpr(t, f);
314+
return addCacheVariableSmart(t, f, result, toCache, type, r);
315+
}
316+
317+
private static ImExpr addCacheVariableSmart(ImTranslator t, ImFunction f, List<ImStmt> result,
318+
Expr toCache, ImType type, WurstType expectedType) {
319+
ImExpr r = toCache.imTranslateExpr(t, f);
320+
r = ExprTranslation.wrapTranslation(toCache, t, r, toCache.attrTypRaw(), expectedType);
321+
return addCacheVariableSmart(t, f, result, toCache, type, r);
322+
}
323+
324+
private static ImExpr addCacheVariableSmart(ImTranslator t, ImFunction f, List<ImStmt> result,
325+
Expr toCache, ImType type, ImExpr r) {
313326
if (r instanceof ImConst) {
314327
return r;
315328
}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,10 @@ public void erasedGenericPrimitiveDefaultsAreNormalizedAtConcreteUse() throws IO
22102210
" let box = new Box<int>",
22112211
" values[box.get()] = 7",
22122212
" if box.get() + 1 == 1",
2213-
" testSuccess()"
2213+
" testSuccess()",
2214+
" for i = 1 to box.get()",
2215+
" testSuccess()",
2216+
" testSuccess()"
22142217
);
22152218
String compiled = compiledLua("erasedGenericPrimitiveDefaultsAreNormalizedAtConcreteUse");
22162219
assertTrue("concrete generic use must normalize an erased integer",

0 commit comments

Comments
 (0)