aboutsummaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-03-03 19:16:09 +0000
committerMichael Williamson <mike@zwobble.org>2025-03-03 19:16:09 +0000
commitc44a2f17b6ca5e53035fe3b21ba6ed0b9107ed2d (patch)
treee4c0eaf8d23e18125b55d2841a8199348ac0582a /src/main/java
parent0fa0028daf69bc80a7e3b3ff9c6491fd12b9cc0b (diff)
Extract Types.underlyingType()
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java17
-rw-r--r--src/main/java/org/shedlang/compiler/types/Types.java10
2 files changed, 11 insertions, 16 deletions
diff --git a/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java b/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java
index 5f229ebc..44fa6d47 100644
--- a/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java
+++ b/src/main/java/org/shedlang/compiler/shid/ShidCodeGen.java
@@ -119,22 +119,7 @@ public class ShidCodeGen {
) {
extraArgumentCount = 1;
// TODO: handle not concrete type
- var methodCallReceiverType = switch (receiverNode.receiver().type()) {
- case SimpleConcreteType concreteType ->
- concreteType;
-
- case ConstructedType<?> constructedType -> {
- if (constructedType.genericType() instanceof SimpleConcreteType concreteType) {
- yield concreteType;
- } else {
- throw new UnsupportedOperationException("TODO");
- }
- }
-
- default -> {
- throw new UnsupportedOperationException("TODO");
- }
- };
+ var methodCallReceiverType = (SimpleConcreteType) Types.underlyingType(receiverNode.receiver().type());
context = context.addInstruction(new ShidMethodLoad(
methodCallReceiverType,
diff --git a/src/main/java/org/shedlang/compiler/types/Types.java b/src/main/java/org/shedlang/compiler/types/Types.java
index ea4e7053..15ef9013 100644
--- a/src/main/java/org/shedlang/compiler/types/Types.java
+++ b/src/main/java/org/shedlang/compiler/types/Types.java
@@ -133,4 +133,14 @@ public class Types {
return BOTTOM;
}
+
+ /// For constructed types, get the underlying type. For all other types,
+ /// just return the same type.
+ public static Type underlyingType(Type type) {
+ if (type instanceof ConstructedType<?> constructedType) {
+ return constructedType.genericType();
+ } else {
+ return type;
+ }
+ }
}