Skip to content

Commit

Permalink
Type checker correction for "while true" loops, fixes #210
Browse files Browse the repository at this point in the history
  • Loading branch information
nickbattle committed Jan 2, 2014
1 parent 7612264 commit e569eeb
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.overture.ast.definitions.AInstanceVariableDefinition;
import org.overture.ast.definitions.PDefinition;
import org.overture.ast.definitions.SClassDefinition;
import org.overture.ast.expressions.ABooleanConstExp;
import org.overture.ast.expressions.AIntLiteralExp;
import org.overture.ast.expressions.ARealLiteralExp;
import org.overture.ast.expressions.AVariableExp;
Expand Down Expand Up @@ -1010,8 +1011,30 @@ public PType caseAWhileStm(AWhileStm node, TypeCheckInfo question)
{
question.qualifiers = null;
node.getExp().apply(THIS, question);
node.setType(node.getStatement().apply(THIS, question));
return node.getType();
PType stype = node.getStatement().apply(THIS, question);

if (node.getExp() instanceof ABooleanConstExp && stype instanceof AUnionType)
{
ABooleanConstExp boolLiteral = (ABooleanConstExp)node.getExp();

if (boolLiteral.getValue().getValue()) // while true do...
{
List<PType> edited = new Vector<PType>();
AUnionType original = (AUnionType)stype;

for (PType t: original.getTypes())
{
if (!(t instanceof AVoidType))
{
edited.add(t);
}
}

stype = AstFactory.newAUnionType(node.getLocation(), edited);
}
}

return stype;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
<message column="12" line="2170" message="Operation returns void value" messageType="error" number="3313" resource="CodegenPP.result"/>
<message column="12" line="2180" message="Operation returns void value" messageType="error" number="3313" resource="CodegenPP.result"/>
<message column="12" line="2197" message="Operation returns void value" messageType="error" number="3313" resource="CodegenPP.result"/>
<message column="9" line="2247" message="Operation returns void value" messageType="error" number="3313" resource="CodegenPP.result"/>
<message column="9" line="2338" message="Operation '(e.hasDeflt)' cannot be called from a function" messageType="error" number="3300" resource="CodegenPP.result"/>
<message column="5" line="2356" message="Operation '(letExp.getDefs)' cannot be called from a function" messageType="error" number="3300" resource="CodegenPP.result"/>
<message column="41" line="2388" message="Operation '(selif.getTest)' cannot be called from a function" messageType="error" number="3300" resource="CodegenPP.result"/>
Expand Down

0 comments on commit e569eeb

Please sign in to comment.