Skip to content

Commit

Permalink
Merge branch 'genericConstructorTest' into 'dev'
Browse files Browse the repository at this point in the history
test generic constructors (new)

See merge request monticore/monticore!1015
  • Loading branch information
SE-FDr committed Aug 28, 2024
2 parents 6be2c5d + 78374ee commit 13a407a
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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>, (T) -> List<T>
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<int>", "List<int>");
checkExpr("new List(1)", "List<int>", "List<int>");
checkExpr("new List(1)", "List<int>");
}

@Test
public void deriveFromArrayCreatorExpression() throws IOException {
checkExpr("new Person[1]", "Person[]");
Expand Down

0 comments on commit 13a407a

Please sign in to comment.