Skip to content

Commit

Permalink
Try to fix issue 3688.
Browse files Browse the repository at this point in the history
  • Loading branch information
9rnsr committed Apr 19, 2011
1 parent 316ba0a commit c56e59d
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions src/statement.c
Expand Up @@ -2314,9 +2314,6 @@ Statement *IfStatement::syntaxCopy()

Statement *IfStatement::semantic(Scope *sc)
{
condition = condition->semantic(sc);
condition = resolveProperties(sc, condition);

// Evaluate at runtime
unsigned cs0 = sc->callSuper;
unsigned cs1;
Expand All @@ -2330,24 +2327,21 @@ Statement *IfStatement::semantic(Scope *sc)
sym->parent = sc->scopesym;
scd = sc->push(sym);

Type *t = arg->type ? arg->type : condition->type;
match = new VarDeclaration(loc, t, arg->ident, NULL);
match = new VarDeclaration(loc, arg->type, arg->ident, new ExpInitializer(loc, condition));
match->noscope = 1;
match->semantic(scd);
if (!scd->insert(match))
assert(0);
match->parent = sc->func;

/* Generate:
* ((arg = condition), arg)
*/
VarExp *v = new VarExp(0, match);
condition = new AssignExp(loc, v, condition);
condition = new CommaExp(loc, condition, v);
DeclarationExp *de = new DeclarationExp(loc, match);
VarExp *ve = new VarExp(0, match);
condition = new CommaExp(loc, de, ve);
condition = condition->semantic(scd);
}
else
{
condition = condition->semantic(sc);
condition = resolveProperties(sc, condition);
scd = sc->push();
}

// Convert to boolean after declaring arg so this works:
// if (S arg = S()) {}
Expand Down

0 comments on commit c56e59d

Please sign in to comment.