Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -213,14 +213,18 @@ public static WurstType normalizedType(Expr e) {
return e.attrExpectedTypRaw().normalize();
}

/**
* The raw parameter type of the overload the call selected. It is not normalised: a parameter of
* an old generic is a bound type parameter, whose toIndex conversion the translation needs.
*/
public static WurstType afterOverloading(Expr e) {
Element parent = e.getParent();
if (parent instanceof Arguments args) {
Element parent2 = args.getParent();
if (parent2 instanceof StmtCall stmtCall) {
return expectedTypeAfterOverloading(e, args, stmtCall).normalize();
return expectedTypeAfterOverloading(e, args, stmtCall);
}
}
return e.attrExpectedTyp();
return e.attrExpectedTypRaw();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public void implicitConversions() {

@Test
public void implicitConversions2() {
test().executeProg(true).testLua(false).lines(
test().executeProg(true).testLua(true).luaOnly(false).lines(
"package test",
" native testSuccess()",
" class Cell<T>",
Expand All @@ -209,6 +209,46 @@ public void implicitConversions2() {
);
}

/**
* A value read from a generic and passed straight back into one: the blaFromIndex of the
* read and the blaToIndex of the write cancel out. They must cancel on both sides, so the
* conversions are not symmetric here (blaToIndex multiplies), which shows a missing one.
*/
private static final String[] NESTED_OLD_GENERIC_CONVERSIONS = {
"package test",
" native testSuccess()",
" class Cell<T>",
" T elem",
" function set(T t)",
" elem = t",
" function get() returns T",
" return elem",
"",
" tuple bla(int z, int y)",
" function blaToIndex(bla b) returns int",
" return b.z * 10",
" function blaFromIndex(int i) returns bla",
" return bla(i div 10, 2)",
" init",
" Cell<bla> c = new Cell<bla>()",
" c.set(bla(5, 3))",
" c.set(c.get())",
" if c.get() == bla(5, 2)",
" testSuccess()",
"endpackage"
};

@Test
public void nestedOldGenericConversionsCancel() {
test().executeProg(true).testLua(true).luaOnly(false).lines(NESTED_OLD_GENERIC_CONVERSIONS);
}

@Test
public void nestedOldGenericConversionsCancelOptimized() {
test().executeProg(true).testLua(true).luaOnly(false).inline().localOptimizations()
.lines(NESTED_OLD_GENERIC_CONVERSIONS);
}

@Test
public void implicitConversions3() {
test().executeProg(true).testLua(false).lines(
Expand Down
Loading