From ad84612e95f0ca701488982430ace111d5f66eab Mon Sep 17 00:00:00 2001 From: nick_battle Date: Sun, 3 Mar 2019 13:49:10 +0000 Subject: [PATCH] Fixes for issue-696 --- .../visitor/TypeCheckerStmVisitor.java | 35 ++++++++++++++----- .../src/test/resources/classesRT/RobotRT | 4 +-- 2 files changed, 29 insertions(+), 10 deletions(-) diff --git a/core/typechecker/src/main/java/org/overture/typechecker/visitor/TypeCheckerStmVisitor.java b/core/typechecker/src/main/java/org/overture/typechecker/visitor/TypeCheckerStmVisitor.java index ce7637d84c..1e69599429 100644 --- a/core/typechecker/src/main/java/org/overture/typechecker/visitor/TypeCheckerStmVisitor.java +++ b/core/typechecker/src/main/java/org/overture/typechecker/visitor/TypeCheckerStmVisitor.java @@ -94,6 +94,8 @@ import org.overture.ast.types.AClassType; import org.overture.ast.types.AFunctionType; import org.overture.ast.types.AOperationType; +import org.overture.ast.types.ASeq1SeqType; +import org.overture.ast.types.ASet1SetType; import org.overture.ast.types.SSetType; import org.overture.ast.types.AUnionType; import org.overture.ast.types.AUnknownType; @@ -196,15 +198,24 @@ public PType caseAForPatternBindStm(AForPatternBindStm node, List defs = getDefinitions(node.getPatternBind()); question.assistantFactory.createPDefinitionListAssistant().typeCheck(defs, THIS, new TypeCheckInfo(question.assistantFactory, question.env, question.scope)); local = new FlatCheckedEnvironment(question.assistantFactory, defs, question.env, question.scope); - } else + PType rt = node.getStatement().apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope)); + + if (!(node.getSeqType() instanceof ASeq1SeqType)) + { + // Add () to the return type, as we may not enter the loop at all + rt = AstFactory.newAUnionType(node.getLocation(), rt, AstFactory.newAVoidType(node.getLocation())); + } + + local.unusedCheck(); + node.setType(rt); + return rt; + } + else { TypeCheckerErrors.report(3223, "Expecting sequence type after 'in'", node.getLocation(), node); + node.setType(AstFactory.newAUnknownType(node.getLocation())); + return node.getType(); } - - PType rt = node.getStatement().apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope)); - local.unusedCheck(); - node.setType(rt); - return rt; } @Override @@ -740,6 +751,13 @@ public PType caseAForAllStm(AForAllStm node, TypeCheckInfo question) Environment local = new FlatCheckedEnvironment(question.assistantFactory, defs, question.env, question.scope); PType rt = node.getStatement().apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope)); + + if (!(st instanceof ASet1SetType)) + { + // Add () to the return type, as we may not enter the loop at all + rt = AstFactory.newAUnionType(node.getLocation(), rt, AstFactory.newAVoidType(node.getLocation())); + } + local.unusedCheck(); node.setType(rt); return rt; @@ -781,9 +799,10 @@ public PType caseAForIndexStm(AForIndexStm node, TypeCheckInfo question) PDefinition vardef = AstFactory.newALocalDefinition(node.getVar().getLocation(), node.getVar(), NameScope.LOCAL, ft); Environment local = new FlatCheckedEnvironment(question.assistantFactory, vardef, question.env, question.scope); PType rt = node.getStatement().apply(THIS, new TypeCheckInfo(question.assistantFactory, local, question.scope)); + AUnionType rtu = AstFactory.newAUnionType(node.getLocation(), rt, AstFactory.newAVoidType(node.getLocation())); local.unusedCheck(); - node.setType(rt); - return rt; + node.setType(rtu); + return rtu; } @Override diff --git a/core/typechecker/src/test/resources/classesRT/RobotRT b/core/typechecker/src/test/resources/classesRT/RobotRT index 1af1d14269..01ff31efc7 100644 --- a/core/typechecker/src/test/resources/classesRT/RobotRT +++ b/core/typechecker/src/test/resources/classesRT/RobotRT @@ -564,9 +564,9 @@ Util`PrintDebug("not"); return p in set dom obs; ); - public GetNextPoint : set of Grid`Point * Grid`Point ==> [Grid`Point] +public GetNextPoint : set of Grid`Point * Grid`Point ==> [Grid`Point] GetNextPoint(neighbours, dest) == - let tmp={p| p in set neighbours + let tmp:set1 of Grid`Point ={p| p in set neighbours & not exists q in set neighbours & Distance(p, dest) > Distance(q, dest)} in