From c44a2f17b6ca5e53035fe3b21ba6ed0b9107ed2d Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 3 Mar 2025 19:16:09 +0000 Subject: Extract Types.underlyingType() --- .../java/org/shedlang/compiler/shid/ShidCodeGen.java | 17 +---------------- src/main/java/org/shedlang/compiler/types/Types.java | 10 ++++++++++ 2 files changed, 11 insertions(+), 16 deletions(-) (limited to 'src/main/java') 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; + } + } } -- cgit v1.2.3