Skip to content

Commit e101e63

Browse files
committed
Use selected overload type for erased arguments
1 parent b94d7e6 commit e101e63

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import de.peeeq.wurstscript.ast.*;
88
import de.peeeq.wurstscript.ast.Element;
99
import de.peeeq.wurstscript.attributes.AttrFuncDef;
10+
import de.peeeq.wurstscript.attributes.AttrExprExpectedType;
1011
import de.peeeq.wurstscript.attributes.CompileError;
1112
import de.peeeq.wurstscript.attributes.AttrImplicitParameter;
1213
import de.peeeq.wurstscript.attributes.names.FuncLink;
@@ -99,7 +100,10 @@ public static ImExpr translate(ExprInstanceOf e, ImTranslator t, ImFunction f) {
99100

100101
private static ImExpr wrapTranslation(Expr e, ImTranslator t, ImExpr translated) {
101102
WurstType actualType = e.attrTypRaw();
102-
WurstType expectedTypRaw = e.attrExpectedTypRaw();
103+
WurstType expectedTypRaw = actualType instanceof WurstTypeBoundTypeParam
104+
&& e.getParent() instanceof Arguments
105+
? AttrExprExpectedType.afterOverloading(e)
106+
: e.attrExpectedTypRaw();
103107
return wrapTranslation(e, t, translated, actualType, expectedTypRaw);
104108
}
105109

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2293,6 +2293,28 @@ public void erasedGenericPrimitiveDefaultsAreNormalizedInCompositeRangeBounds()
22932293
compiled.contains("__wurst_ensureInt(Box_Box_get(box))"));
22942294
}
22952295

2296+
@Test
2297+
public void erasedGenericPrimitiveDefaultsUseTheSelectedOverload() throws IOException {
2298+
test().testLua(true).executeProg().lines(
2299+
"package Test",
2300+
"native testSuccess()",
2301+
"class Box<T:>",
2302+
" T value",
2303+
" function get() returns T",
2304+
" return value",
2305+
"function consume(int value)",
2306+
" if value == 0",
2307+
" testSuccess()",
2308+
"function consume(string value)",
2309+
"init",
2310+
" let box = new Box<int>",
2311+
" consume(box.get())"
2312+
);
2313+
String compiled = compiledLua("erasedGenericPrimitiveDefaultsUseTheSelectedOverload");
2314+
assertTrue("selected integer overload arguments must normalize erased primitive values",
2315+
compiled.contains("__wurst_ensureInt(Box_Box_get(box))"));
2316+
}
2317+
22962318
/**
22972319
* Seeded boundary corpus for the type-assurance change. Each case varies
22982320
* the primitive type, literal value, and array slot while checking the two

0 commit comments

Comments
 (0)