From bbee238f6f5989dbcfd2790d7310aad5664336ec Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 2 Aug 2026 12:00:52 +0100 Subject: Store source for sum types --- .../compiler/analysis/ArbitraryValueAnalysisTests.java | 8 +++++--- .../compiler/typechecker/TypeCheckerSubtypingTests.java | 10 +++++++--- .../compiler/typechecker/TypeCheckerSumDefinitionTests.java | 3 ++- 3 files changed, 14 insertions(+), 7 deletions(-) (limited to 'src/test') diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/analysis/ArbitraryValueAnalysisTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/analysis/ArbitraryValueAnalysisTests.java index 30dbc7b..526f6bb 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/analysis/ArbitraryValueAnalysisTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/analysis/ArbitraryValueAnalysisTests.java @@ -21,7 +21,7 @@ public class ArbitraryValueAnalysisTests { public void whenTypeHasNoVariantsThenErrorIsThrown() { var sumType = new SumType(NamespaceName.of(), "X"); var typesInfo = TypesInfoInMemory.empty(); - typesInfo.defineSumType(sumType, List.of(), List.of()); + typesInfo.defineSumType(sumType, List.of(), List.of(), NullSource.INSTANCE); var error = assertThrows( SumTypeHasNoVariantsError.class, @@ -41,7 +41,8 @@ public class ArbitraryValueAnalysisTests { List.of( new SumVariant(0, variantType, variantType) ), - List.of() + List.of(), + NullSource.INSTANCE ); typesInfo.defineStructType(variantType, Optional.of(List.of( new Field("x", sumType, NullSource.INSTANCE) @@ -67,7 +68,8 @@ public class ArbitraryValueAnalysisTests { new SumVariant(0, recursiveVariantType, recursiveVariantType), new SumVariant(1, nonRecursiveVariantType, nonRecursiveVariantType) ), - List.of() + List.of(), + NullSource.INSTANCE ); typesInfo.defineStructType(recursiveVariantType, Optional.of(List.of( new Field("x", sumType, NullSource.INSTANCE) diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSubtypingTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSubtypingTests.java index 7080b81..f22bc3e 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSubtypingTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSubtypingTests.java @@ -1,6 +1,7 @@ package org.zwobble.hobgoblin.compiler.typechecker; import org.junit.jupiter.api.Test; +import org.zwobble.hobgoblin.compiler.sources.NullSource; import org.zwobble.hobgoblin.compiler.types.*; import java.util.List; @@ -42,7 +43,8 @@ public class TypeCheckerSubtypingTests { new SumVariant(0, variantType1, variantType1), new SumVariant(1, variantType2, variantType2) ), - List.of() + List.of(), + NullSource.INSTANCE ); var isSubtype = isSubtype(variantType1, sumType, typesInfo); @@ -63,7 +65,8 @@ public class TypeCheckerSubtypingTests { new SumVariant(0, variantType1, variantType1), new SumVariant(1, variantType2, variantType2) ), - List.of() + List.of(), + NullSource.INSTANCE ); var otherSumType = new SumType(NamespaceName.of(), "Shape3D"); @@ -71,7 +74,8 @@ public class TypeCheckerSubtypingTests { typesInfo.defineSumType( otherSumType, List.of(new SumVariant(0, otherVariantType, otherVariantType)), - List.of() + List.of(), + NullSource.INSTANCE ); var isSubtype = isSubtype(variantType1, otherSumType, typesInfo); diff --git a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSumDefinitionTests.java b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSumDefinitionTests.java index 96f2e5d..ef67cb5 100644 --- a/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSumDefinitionTests.java +++ b/src/test/java/org/zwobble/hobgoblin/compiler/typechecker/TypeCheckerSumDefinitionTests.java @@ -322,7 +322,8 @@ public class TypeCheckerSumDefinitionTests { namespaceContext.defineSumType( sumType, List.of(new SumVariant(0, variantType, variantType)), - List.of(new Field("area", int32Type, NullSource.INSTANCE)) + List.of(new Field("area", int32Type, NullSource.INSTANCE)), + NullSource.INSTANCE ); assertThrows( -- cgit v1.2.3