aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/types/CommonSupertypeTests.java25
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));
+ }
}