From 0d3b69afbda09e5140b05b8bb57100338da6c6c0 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 18 May 2026 23:41:24 +0100 Subject: Track struct field types --- .../TypeCheckerStructDefinitionTests.java | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java index 336c496..8967601 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java @@ -11,10 +11,10 @@ import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedNamespaceNode; import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructDefinitionNode; import org.zwobble.hobgoblin.compiler.ast.untyped.UntypedStructFieldDefinitionNode; import org.zwobble.hobgoblin.compiler.sources.NullSource; +import org.zwobble.hobgoblin.compiler.types.Field; import org.zwobble.hobgoblin.compiler.types.NamespaceName; import org.zwobble.hobgoblin.compiler.types.SimpleNativeType; import org.zwobble.hobgoblin.compiler.types.StructType; -import org.zwobble.hobgoblin.compiler.types.TypeLevelValueType; import java.util.List; @@ -58,13 +58,13 @@ public class TypeCheckerStructDefinitionTests { DocComment.EMPTY, NullSource.INSTANCE ); - var context = TypeCheckerContextArb.namespaceContext(NamespaceName.of("a", "b")); - context.declare(int32Type.name()); - context.define(int32Type.name(), new TypeLevelValueType(int32Type)); - context.declare(int64Type.name()); - context.define(int64Type.name(), new TypeLevelValueType(int64Type)); + var globalContext = TypeCheckerGlobalContext.initial(); + globalContext.addNativeType(int32Type); + globalContext.addNativeType(int64Type); + var namespaceName = NamespaceName.of("a", "b"); + var namespaceContext = globalContext.enterNamespace(namespaceName); - var typed = typeCheckNamespaceStatement(untyped, context); + var typed = typeCheckNamespaceStatement(untyped, namespaceContext); assertThat(typed, instanceOf( TypedStructDefinitionNode.class, @@ -91,6 +91,14 @@ public class TypeCheckerStructDefinitionTests { ) ) )); + var typesInfo = globalContext.toTypesInfo(); + assertThat( + typesInfo.fieldsOf(new StructType(namespaceName, "X")), + isSequence( + equalTo(new Field("a", int32Type)), + equalTo(new Field("b", int64Type)) + ) + ); } @Test -- cgit v1.2.3