From 75df30e9b9a06424f9fa96c32733d557f8df3608 Mon Sep 17 00:00:00 2001 From: Jason Steving Date: Tue, 27 Jun 2023 11:13:07 -0700 Subject: [PATCH] Quick Fix in Dynamic Dispatch Previously if there was a contract def that only had impls defined such that dynamic dispatch was supported over a subset of args, you'd run into an internal compiler error (NPE). That's fixed. --- .../statements/StmtListNode.java | 3 +-- .../statements/contracts/ContractDefinitionStmt.java | 7 +++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/java/com/claro/intermediate_representation/statements/StmtListNode.java b/src/java/com/claro/intermediate_representation/statements/StmtListNode.java index 34d20bb3..e3cadb86 100644 --- a/src/java/com/claro/intermediate_representation/statements/StmtListNode.java +++ b/src/java/com/claro/intermediate_representation/statements/StmtListNode.java @@ -42,8 +42,7 @@ public void assertExpectedExprTypes(ScopedHeap scopedHeap) throws ClaroTypeExcep // TODO(steving) Find some way to make this assertion in the CUP parsing phase itself. Once we start // implementing better error messages with line numbers etc, I get a feeling that // throwing this manner of error here will make it hard to get line numbers right. - throw new ClaroParserException( - "Unreachable statements following a return/break stmt are not allowed." + curr.getChildren().get(0)); + throw new ClaroParserException("Unreachable statements following a return/break stmt are not allowed."); } Stmt currStmt = ((Stmt) curr.getChildren().get(0)); diff --git a/src/java/com/claro/intermediate_representation/statements/contracts/ContractDefinitionStmt.java b/src/java/com/claro/intermediate_representation/statements/contracts/ContractDefinitionStmt.java index 4fc93803..ecb1c9a9 100644 --- a/src/java/com/claro/intermediate_representation/statements/contracts/ContractDefinitionStmt.java +++ b/src/java/com/claro/intermediate_representation/statements/contracts/ContractDefinitionStmt.java @@ -679,8 +679,11 @@ private StringBuilder generateDynamicDispatchHelperForContractProcedure(String p .requiredContextualOutputTypeAssertionTypeParamNames .contains(this.typeParamNames.get(n)) || - this.contractProceduresSupportingDynamicDispatchOverArgsWhenGenericReturnTypeInferenceRequired - .get(procedureName).values().stream().anyMatch(i -> n == i)) { + Optional.ofNullable( + this.contractProceduresSupportingDynamicDispatchOverArgsWhenGenericReturnTypeInferenceRequired + .get(procedureName)) + .map(m -> m.values().stream().anyMatch(i -> n == i)) + .orElse(false)) { return String.format("$%s_vtableKey", this.typeParamNames.get(n)); } Type onlyConcreteTypeForCurrTypeParam =