diff options
| author | Michael Williamson <mike@zwobble.org> | 2024-01-07 18:05:55 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2024-01-07 18:06:59 +0000 |
| commit | 2d3d2c5f27a38c25e6d697c8635c38655f1a9728 (patch) | |
| tree | 602f0f69cdf3747b4ca7bdd244368cf0adbdadcd /src/test/java | |
| parent | 870aa25e96683a6686b019e40e1fe611fd36c69f (diff) | |
Update commonSupertype to handle supertype of sum and its variants
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/types/CommonSupertypeTests.java | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/test/java/org/shedlang/compiler/types/CommonSupertypeTests.java b/src/test/java/org/shedlang/compiler/types/CommonSupertypeTests.java index 1b9873a6..fb9a14c5 100644 --- a/src/test/java/org/shedlang/compiler/types/CommonSupertypeTests.java +++ b/src/test/java/org/shedlang/compiler/types/CommonSupertypeTests.java @@ -83,4 +83,29 @@ public class CommonSupertypeTests { assertThat(result, equalTo(sumType)); } + + @Test + public void commonSupertypeOfSumTypeAndVariantOfThatSumTypeIsThatSumType() { + var namespaceName = NamespaceName.of("Example"); + var variantType1 = Types.struct(namespaceName, "Variant1"); + var variantType2 = Types.struct(namespaceName, "Variant2"); + var sumType = Types.sum(namespaceName, "Sum"); + var typeInfos = TypeInfos.EMPTY + .addSumTypeInfo(sumType, new SumTypeInfo(P.orderedSet( + variantType1, + variantType2 + ))); + + var result1 = Types.commonSupertype( + List.of(sumType, variantType2), + typeInfos + ); + var result2 = Types.commonSupertype( + List.of(variantType2, sumType), + typeInfos + ); + + assertThat(result1, equalTo(sumType)); + assertThat(result2, equalTo(sumType)); + } } |
