Skip to content

Commit

Permalink
Fixes for issue-696
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbattle committed Mar 3, 2019
1 parent f3520f6 commit ad84612
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
Expand Up @@ -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;
Expand Down Expand Up @@ -196,15 +198,24 @@ public PType caseAForPatternBindStm(AForPatternBindStm node,
List<PDefinition> 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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions core/typechecker/src/test/resources/classesRT/RobotRT
Expand Up @@ -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
Expand Down

0 comments on commit ad84612

Please sign in to comment.