From b42facd34eef8747a0c2c79555ac70bb60175e9e Mon Sep 17 00:00:00 2001 From: nick_battle Date: Sat, 31 Oct 2020 11:50:42 +0000 Subject: [PATCH 1/2] Check for invariant types when converting function values, fixes #761 --- .../overture/interpreter/values/FunctionValue.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/core/interpreter/src/main/java/org/overture/interpreter/values/FunctionValue.java b/core/interpreter/src/main/java/org/overture/interpreter/values/FunctionValue.java index b6c3fcce08..ac2d4d78da 100644 --- a/core/interpreter/src/main/java/org/overture/interpreter/values/FunctionValue.java +++ b/core/interpreter/src/main/java/org/overture/interpreter/values/FunctionValue.java @@ -50,6 +50,7 @@ import org.overture.ast.patterns.APatternTypePair; import org.overture.ast.patterns.PPattern; import org.overture.ast.types.AFunctionType; +import org.overture.ast.types.ANamedInvariantType; import org.overture.ast.types.PType; import org.overture.ast.util.Utils; import org.overture.config.Settings; @@ -804,7 +805,7 @@ protected Value convertValueTo(PType to, Context ctxt, Set done) List domain = tc.narrowest(type.getParameters(), restrictedType.getParameters()); PType range = tc.narrowest(type.getResult(), restrictedType.getResult()); AFunctionType newType = AstFactory.newAFunctionType(location, true, domain, range); - + // Create a new function with the narrowest domain/range. FunctionValue restricted = new FunctionValue(location, name, newType, paramPatternList, body, precondition, postcondition, @@ -812,7 +813,15 @@ protected Value convertValueTo(PType to, Context ctxt, Set done) measureValues, result); restricted.typeValues = typeValues; - return restricted; + + if (to instanceof ANamedInvariantType) + { + return new InvariantValue((ANamedInvariantType)to, restricted, ctxt); + } + else + { + return restricted; + } } } } From 656ece8aa7d9bbcdb9c1c5168169e64f997ee5ad Mon Sep 17 00:00:00 2001 From: nick_battle Date: Tue, 3 Nov 2020 11:02:20 +0000 Subject: [PATCH 2/2] Correct check of function parameter patterns and arguments, fixes #762 --- .../typechecker/utilities/pattern/AllDefinitionLocator.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/typechecker/src/main/java/org/overture/typechecker/utilities/pattern/AllDefinitionLocator.java b/core/typechecker/src/main/java/org/overture/typechecker/utilities/pattern/AllDefinitionLocator.java index 390b363e86..249126899c 100644 --- a/core/typechecker/src/main/java/org/overture/typechecker/utilities/pattern/AllDefinitionLocator.java +++ b/core/typechecker/src/main/java/org/overture/typechecker/utilities/pattern/AllDefinitionLocator.java @@ -200,7 +200,7 @@ public List caseARecordPattern(ARecordPattern pattern, ARecordInvariantType pattype = af.createPTypeAssistant().getRecord(type, pattern.getLocation().getModule()); - if (!af.createPTypeAssistant().isType(question.ptype, pattype.getClass())) + if (!af.getTypeComparator().compatible(pattype, question.ptype)) { TypeCheckerErrors.report(3201, "Matching expression is not a compatible record type", pattern.getLocation(), pattern); TypeCheckerErrors.detail2("Pattern type", type, "Expression type", question.ptype);