Skip to content

Commit

Permalink
Fixing While boolean condition #36
Browse files Browse the repository at this point in the history
The problem was the fact that we didn't properly derenference the condition.
  • Loading branch information
lucteo committed Mar 14, 2017
1 parent c864e5c commit cb04c2e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Feather/src/Api/Feather_Nodes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -974,6 +974,17 @@ using namespace Feather;
if ( !Feather_isTestable(condition) )
REP_ERROR_RET(nullptr, condition->location, "The condition of the while is not Testable");

// Dereference the condition as much as possible
while ( condition->type && condition->type->numReferences > 0 )
{
condition = Feather_mkMemLoad(condition->location, condition);
Nest_setContext(condition, Nest_childrenContext(node));
if ( !Nest_semanticCheck(condition) )
return nullptr;
}
at(node->children, 0) = condition;
// TODO (while): Remove this dereference from here

if ( Feather_nodeEvalMode(node) == modeCt )
{
if ( !Feather_isCt(condition) )
Expand Down
8 changes: 8 additions & 0 deletions tests/Bugs/WhileVarCond.spr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
fun sprMain
var a: Bool
a = true
var ra: @Bool = a
while a
break
while ra
break
1 change: 1 addition & 0 deletions tests/tests.in
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ Bugs/SpecializationOnCt.spr: Bugs - specialization on CT vs RT
# Bugs/Overload.spr: Bugs - overload resolution fails
Bugs/StaticGlobal.spr: Bugs - static vars, global vars, static ctor
Bugs/VectorOfCtClass.spr: Bugs - vectors of CT-only classes
Bugs/WhileVarCond.spr: Bugs - while condition is a variable or a reference

# AlgoProblems/P1_Collatz.spr: Algo problems - P1. Collatz sequences
Examples/Power.spr: Examples: Powers
Expand Down

0 comments on commit cb04c2e

Please sign in to comment.