From 4bc8addad4bf16b86bc569696e6dada09375cc61 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Fri, 29 Dec 2023 11:22:04 +0000 Subject: Support (no-op) type substitution for struct types --- .../java/org/shedlang/compiler/types/TypeSubstitution.java | 5 ++--- .../org/shedlang/compiler/types/TypeSubstitutionTests.java | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) (limited to 'src') 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 @@ -153,6 +153,20 @@ public class TypeSubstitutionTests { assertThat(result, equalTo(Types.STRING)); } + @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( -- cgit v1.2.3