From bd2643ba9d5f6245f6363a199a1ceaf9c8a075c7 Mon Sep 17 00:00:00 2001 From: nick_battle Date: Thu, 29 Oct 2020 11:20:01 +0000 Subject: [PATCH] Use re-stated types in definition imports (see #760) --- .../utilities/DefinitionTypeFinder.java | 27 +++++++++++++++++-- .../expression/ImportDefinitionFinder.java | 5 ++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/core/typechecker/src/main/java/org/overture/typechecker/utilities/DefinitionTypeFinder.java b/core/typechecker/src/main/java/org/overture/typechecker/utilities/DefinitionTypeFinder.java index 2df8304b6c..5180d7f959 100644 --- a/core/typechecker/src/main/java/org/overture/typechecker/utilities/DefinitionTypeFinder.java +++ b/core/typechecker/src/main/java/org/overture/typechecker/utilities/DefinitionTypeFinder.java @@ -52,6 +52,7 @@ import org.overture.ast.definitions.SClassDefinition; import org.overture.ast.factory.AstFactory; import org.overture.ast.node.INode; +import org.overture.ast.types.AFunctionType; import org.overture.ast.types.AUnionType; import org.overture.ast.types.PType; import org.overture.typechecker.assistant.ITypeCheckerAssistantFactory; @@ -146,7 +147,18 @@ public PType caseAImplicitOperationDefinition( public PType caseAImportedDefinition(AImportedDefinition node) throws AnalysisException { - return ((AImportedDefinition) node).getDef().apply(THIS); + PType type = node.getType(); + + if (type != null && !(type instanceof AFunctionType)) + { + // Only for non-function types (polymorphic params cause trouble) + // See bug #760 + return type; + } + else + { + return ((AImportedDefinition) node).getDef().apply(THIS); + } } public static void checkSuperDefinition(AInheritedDefinition d) @@ -231,7 +243,18 @@ public PType caseAPerSyncDefinition(APerSyncDefinition node) public PType caseARenamedDefinition(ARenamedDefinition node) throws AnalysisException { - return ((ARenamedDefinition) node).getDef().apply(THIS); + PType type = node.getType(); + + if (type != null && !(type instanceof AFunctionType)) + { + // Only for non-function types (polymorphic params cause trouble) + // See bug #760 + return type; + } + else + { + return ((ARenamedDefinition) node).getDef().apply(THIS); + } } @Override diff --git a/core/typechecker/src/main/java/org/overture/typechecker/utilities/expression/ImportDefinitionFinder.java b/core/typechecker/src/main/java/org/overture/typechecker/utilities/expression/ImportDefinitionFinder.java index e44060738d..30818d5d96 100644 --- a/core/typechecker/src/main/java/org/overture/typechecker/utilities/expression/ImportDefinitionFinder.java +++ b/core/typechecker/src/main/java/org/overture/typechecker/utilities/expression/ImportDefinitionFinder.java @@ -132,6 +132,11 @@ public List defaultSValueImport(SValueImport imp, { expdef = AstFactory.newAImportedDefinition(imp.getLocation(), expdef); } + + if (imp.getImportType() != null) + { + expdef.setType(imp.getImportType()); + } list.add(expdef); }