From 4316c4a80e33ceea40990472f215440a6f678623 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 31 Dec 2023 10:05:30 +0000 Subject: Add basic inference of type level args --- .../compiler/typechecker/TypeCheckerCallTests.java | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'src/test/java') diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java index 8fb1faf5..1dcfc36a 100644 --- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java +++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java @@ -423,4 +423,46 @@ public class TypeCheckerCallTests { .withType(Types.constructedType(typeConstructor, List.of(Types.STRING))) ); } + + @Test + public void canCallGenericStructWithImplicitTypeArgs() { + var untyped = UntypedCallNode.builder() + .withReceiver(Untyped.reference("Box")) + .addNamedArg(Untyped.namedArg("value", Untyped.stringLiteral("Bob"))) + .build(); + var structType = Types.struct(NamespaceName.of("Example"), "Box"); + var typeConstructor = Types.typeConstructor( + List.of(TypeParam.forStructType(structType, "T")), + structType + ); + var structTypeInfo = StructTypeInfo.builder() + .addField("value", TypeParam.forStructType(structType, "T")) + .build(); + var context = TypeCheckerContext.EMPTY + .enterGlobal(P.map( + Map.entry("String", Types.metaType(Types.STRING)), + Map.entry("Box", Types.typeConstructorType(typeConstructor)) + )) + .addStructTypeInfo(structType, structTypeInfo); + + var typed = typeCheckExpression(untyped, context); + + assertThat( + typed.value(), + isTypedCallNode() + .withReceiver(isTypedReferenceNode( + "Box", + Types.typeConstructorType(typeConstructor) + )) + .withArgs( + isTypedArgsNode() + .withPositional(isSequence()) + .withNamed(isSequence( + isTypedNamedArgNode("value", isTypedStringLiteralNode("Bob")) + )) + ) + .withHasEffects(false) + .withType(Types.constructedType(typeConstructor, List.of(Types.STRING))) + ); + } } -- cgit v1.2.3