diff --git a/monticore-grammar/src/test/java/de/monticore/types3/UglyExpressionsTypeVisitorTest.java b/monticore-grammar/src/test/java/de/monticore/types3/UglyExpressionsTypeVisitorTest.java index a86f4605d0..d3c49be01e 100644 --- a/monticore-grammar/src/test/java/de/monticore/types3/UglyExpressionsTypeVisitorTest.java +++ b/monticore-grammar/src/test/java/de/monticore/types3/UglyExpressionsTypeVisitorTest.java @@ -4,6 +4,7 @@ import de.monticore.symbols.oosymbols._symboltable.IOOSymbolsGlobalScope; import de.monticore.symbols.oosymbols._symboltable.IOOSymbolsScope; import de.monticore.symbols.oosymbols._symboltable.MethodSymbol; +import de.monticore.types.check.SymTypeExpressionFactory; import de.monticore.types3.util.DefsVariablesForTests; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -13,6 +14,7 @@ import static de.monticore.types3.util.DefsTypesForTests._floatSymType; import static de.monticore.types3.util.DefsTypesForTests._intSymType; import static de.monticore.types3.util.DefsTypesForTests._personSymType; +import static de.monticore.types3.util.DefsTypesForTests._unboxedListSymType; import static de.monticore.types3.util.DefsTypesForTests.method; public class UglyExpressionsTypeVisitorTest extends AbstractTypeVisitorTest { @@ -120,6 +122,26 @@ public void testInvalidClassCreatorExpression2() throws IOException { checkErrorExpr("new R\"h(e|a)llo\"()", "0xFD552"); } + @Test + public void testGenericConstructorClassCreatorExpression() throws IOException { + IOOSymbolsGlobalScope gs = OOSymbolsMill.globalScope(); + IOOSymbolsScope listScope = (IOOSymbolsScope) + gs.resolveType("List").get().getSpannedScope(); + // constructors: () -> List, (T) -> List + MethodSymbol constructor0 = method("List", _unboxedListSymType); + constructor0.setIsConstructor(true); + listScope.add(constructor0); + MethodSymbol constructor1 = method("List", _unboxedListSymType, + SymTypeExpressionFactory.createTypeVariable(listScope.getTypeVarSymbols().values().get(0)) + ); + constructor1.setIsConstructor(true); + listScope.add(constructor1); + + checkExpr("new List()", "List", "List"); + checkExpr("new List(1)", "List", "List"); + checkExpr("new List(1)", "List"); + } + @Test public void deriveFromArrayCreatorExpression() throws IOException { checkExpr("new Person[1]", "Person[]");