diff options
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/org/shedlang/compiler/types/CommonSupertypeTests.java | 21 |
1 files changed, 21 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 a30ecb24..1b9873a6 100644 --- a/src/test/java/org/shedlang/compiler/types/CommonSupertypeTests.java +++ b/src/test/java/org/shedlang/compiler/types/CommonSupertypeTests.java @@ -2,6 +2,7 @@ package org.shedlang.compiler.types; import org.junit.jupiter.api.Test; import org.shedlang.compiler.typechecker.TypeInfos; +import org.shedlang.compiler.util.P; import java.util.List; @@ -62,4 +63,24 @@ public class CommonSupertypeTests { assertThat(result, equalTo(Types.INT)); } + + @Test + public void commonSupertypeOfVariantsOfSameSumTypeIsThatSumType() { + 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 result = Types.commonSupertype( + List.of(variantType1, variantType2), + typeInfos + ); + + assertThat(result, equalTo(sumType)); + } } |
