aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-29 11:22:04 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-29 11:22:04 +0000
commit4bc8addad4bf16b86bc569696e6dada09375cc61 (patch)
tree13c05aa1ab0c635f84ed082415ae051466307262 /src
parent0af716f40b0073089027b7082f1b4054cd808d64 (diff)
Support (no-op) type substitution for struct types
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/shedlang/compiler/types/TypeSubstitution.java5
-rw-r--r--src/test/java/org/shedlang/compiler/types/TypeSubstitutionTests.java14
2 files changed, 16 insertions, 3 deletions
diff --git a/src/main/java/org/shedlang/compiler/types/TypeSubstitution.java b/src/main/java/org/shedlang/compiler/types/TypeSubstitution.java
index a6719d17..5d2b7077 100644
--- a/src/main/java/org/shedlang/compiler/types/TypeSubstitution.java
+++ b/src/main/java/org/shedlang/compiler/types/TypeSubstitution.java
@@ -33,9 +33,8 @@ public class TypeSubstitution {
case StringType stringType -> type;
- case StructType structType -> {
- throw new UnsupportedOperationException("TODO");
- }
+ case StructType structType ->
+ type;
case SumType sumType -> {
throw new UnsupportedOperationException("TODO");
diff --git a/src/test/java/org/shedlang/compiler/types/TypeSubstitutionTests.java b/src/test/java/org/shedlang/compiler/types/TypeSubstitutionTests.java
index e9b04a95..d6713ee0 100644
--- a/src/test/java/org/shedlang/compiler/types/TypeSubstitutionTests.java
+++ b/src/test/java/org/shedlang/compiler/types/TypeSubstitutionTests.java
@@ -154,6 +154,20 @@ public class TypeSubstitutionTests {
}
@Test
+ public void substitutingStructDoesNothing() {
+ var typeSubstitutionMap = TypeSubstitutionMap.of(
+ Map.entry(TypeParam.forStructType(STRUCT_TYPE, "T"), Types.INT)
+ );
+
+ var result = TypeSubstitution.substitute(
+ Types.struct(NamespaceName.of("A"), "B"),
+ typeSubstitutionMap
+ );
+
+ assertThat(result, equalTo(Types.struct(NamespaceName.of("A"), "B")));
+ }
+
+ @Test
public void substitutingTopDoesNothing() {
var typeSubstitutionMap = TypeSubstitutionMap.of(
Map.entry(TypeParam.forStructType(STRUCT_TYPE, "T"), Types.INT)