diff options
| author | Michael Williamson <mike@zwobble.org> | 2026-05-18 23:41:24 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2026-05-18 23:41:24 +0100 |
| commit | 0d3b69afbda09e5140b05b8bb57100338da6c6c0 (patch) | |
| tree | ef0936b3d2e3a3a4644c5b106fa35c400b871069 /src/test/java/org | |
| parent | a7fc927123bd445dec6df5acb89b5bd0551bf064 (diff) | |
Track struct field types
Diffstat (limited to 'src/test/java/org')
| -rw-r--r-- | src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerStructDefinitionTests.java | 22 |
1 files changed, 15 insertions, 7 deletions
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 |
