aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-09-30 11:22:24 +0100
committerMichael Williamson <mike@zwobble.org>2023-09-30 11:22:24 +0100
commit6d18d2156ae4063eee04ca467727e0ec0c4404cc (patch)
treeca2da4b887cfe221247621670a010eee1ad18a4a /src/main/java/org
parent107ce1646e24b0d30f7fc42e831a7e5f03daecc3 (diff)
Add SumType
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/shedlang/compiler/types/SumType.java11
-rw-r--r--src/main/java/org/shedlang/compiler/types/Type.java2
2 files changed, 12 insertions, 1 deletions
diff --git a/src/main/java/org/shedlang/compiler/types/SumType.java b/src/main/java/org/shedlang/compiler/types/SumType.java
new file mode 100644
index 00000000..8c293fca
--- /dev/null
+++ b/src/main/java/org/shedlang/compiler/types/SumType.java
@@ -0,0 +1,11 @@
+package org.shedlang.compiler.types;
+
+/**
+ * A discriminated union of several different types.
+ */
+public record SumType(NamespaceName namespaceName, String name) implements Type {
+ @Override
+ public String describe() {
+ return namespaceName.toString() + "." + name;
+ }
+}
diff --git a/src/main/java/org/shedlang/compiler/types/Type.java b/src/main/java/org/shedlang/compiler/types/Type.java
index b88cf42b..a1de4068 100644
--- a/src/main/java/org/shedlang/compiler/types/Type.java
+++ b/src/main/java/org/shedlang/compiler/types/Type.java
@@ -6,5 +6,5 @@ package org.shedlang.compiler.types;
* found through auxiliary data.
*/
public sealed interface Type extends TypeLevelValue
- permits BoolType, BottomType, FunctionType, IntType, NamespaceType, StringType, StructType, TopType, TupleType, TypeLevelValueType, UnitType {
+ permits BoolType, BottomType, FunctionType, IntType, NamespaceType, StringType, StructType, SumType, TopType, TupleType, TypeLevelValueType, UnitType {
}