Skip to content

Commit d66d9e8

Browse files
authored
Fix too early specification of generic types (#1130)
1 parent 9ce6d7e commit d66d9e8

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,12 +582,12 @@ public void visit(ImTypeArgument ta) {
582582
@Override
583583
public void visit(ImNull e) {
584584
ImType newT = transformType(e.getType(), generics, typeVars);
585-
newT = specializeType(newT);
586585
e.setType(newT);
587586

588587
ImExpr safe = specializeNullInitializer(e, newT);
589588
if (safe != e) {
590589
e.replaceBy(safe);
590+
return;
591591
}
592592
super.visit(e);
593593
}

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2023,5 +2023,35 @@ public void fullArrayListTest() throws IOException {
20232023
testAssertOkFileWithStdLib(new File(TEST_DIR + "arrayList.wurst"), true);
20242024
}
20252025

2026+
@Test
2027+
public void genericNullComparison() {
2028+
testAssertOkLinesWithStdLib(true,
2029+
"package test",
2030+
"import NoWurst",
2031+
"import ClosureTimers",
2032+
"native testSuccess()",
2033+
"public class Reference<T:>",
2034+
" T val",
2035+
" construct(T val)",
2036+
" this.val = val",
2037+
" function into() returns T",
2038+
" let rval = val",
2039+
" destroy this",
2040+
" return rval",
2041+
"",
2042+
"var r = new Reference(0.0)",
2043+
"",
2044+
"init",
2045+
" // force member access on the global",
2046+
" doAfter(.1) ->",
2047+
" r.val = 1.0",
2048+
" if r != null and not r == null and r.into() == 1.0",
2049+
" testSuccess()",
2050+
" testSuccess() // to make compiler happy",
2051+
"endpackage"
2052+
);
2053+
}
2054+
2055+
20262056

20272057
}

0 commit comments

Comments
 (0)