aboutsummaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-01-07 17:50:25 +0000
committerMichael Williamson <mike@zwobble.org>2024-01-07 17:50:25 +0000
commit870aa25e96683a6686b019e40e1fe611fd36c69f (patch)
tree4bf8a64ec580972c0960b601c414902858fc2a77 /src/test/java
parent6c32b35bd7711d1fb73bf505a0f2638b4a40e507 (diff)
Update commonSupertype to consider sum types
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/shedlang/compiler/types/CommonSupertypeTests.java21
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));
+ }
}