diff options
| author | Michael Williamson <mike@zwobble.org> | 2023-12-26 18:17:59 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2023-12-26 18:17:59 +0000 |
| commit | e0f232e9ad7fbe304e99bb4e880c761f06255791 (patch) | |
| tree | e8b85f8d455430474d4a7f85feef62dd6feab215 /src/test/java | |
| parent | 92431737b02154be7500d5df18a5b4fc883c5fd1 (diff) | |
Support constructed struct type constructors
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java index 50c74944..8fb1faf5 100644 --- a/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java +++ b/src/test/java/org/shedlang/compiler/typechecker/TypeCheckerCallTests.java @@ -378,4 +378,49 @@ public class TypeCheckerCallTests { .withType(structType) ); } + + @Test + public void canCallGenericStructWithExplicitTypeArgs() { + var untyped = UntypedCallNode.builder() + .withReceiver(Untyped.reference("Box")) + .withTypeLevelArgs(List.of( + Untyped.typeLevelReference("String") + )) + .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))) + ); + } } |
