Skip to content

Commit

Permalink
Merge pull request #3024 from yebblies/issue199
Browse files Browse the repository at this point in the history
Issue 199 - Label causes scope to collapse into parent
  • Loading branch information
WalterBright committed Dec 28, 2013
2 parents 252b0d2 + d0bfeca commit ced168b
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 10 deletions.
5 changes: 4 additions & 1 deletion src/parse.c
Expand Up @@ -3930,7 +3930,10 @@ Statement *Parser::parseStatement(int flags, const utf8_t** endPtr)
Identifier *ident = token.ident;
nextToken();
nextToken();
s = parseStatement(PSsemi_ok);
if (token.value == TOKlcurly)
s = parseStatement(PScurly | PSscope);
else
s = parseStatement(PSsemi_ok);
s = new LabelStatement(loc, ident, s);
break;
}
Expand Down
20 changes: 11 additions & 9 deletions test/compilable/interpret3.d
Expand Up @@ -2738,16 +2738,18 @@ static assert({ E8365[2][2][2] x; return x[0][0][0]; }() == E8365.first);
int bug4448()
{
int n=2;
L1:{ switch(n)
L1: do
{
case 5:
return 7;
default:
n = 5;
break L1;
}
int w = 7;
}
switch(n)
{
case 5:
return 7;
default:
n = 5;
break L1;
}
int w = 7;
} while (0);
return 3;
}

Expand Down
26 changes: 26 additions & 0 deletions test/fail_compilation/fail4448.d
@@ -0,0 +1,26 @@
/*
TEST_OUTPUT:
---
fail_compilation/fail4448.d(19): Error: label 'L1' has no break
fail_compilation/fail4448.d(26): called from here: bug4448()
fail_compilation/fail4448.d(26): while evaluating: static assert(bug4448() == 3)
---
*/

int bug4448()
{
int n=2;
L1:{ switch(n)
{
case 5:
return 7;
default:
n = 5;
break L1;
}
int w = 7;
}
return 3;
}

static assert(bug4448()==3);
14 changes: 14 additions & 0 deletions test/runnable/xtest46.d
Expand Up @@ -4490,6 +4490,19 @@ void test6630()
assert(a.b !is null);
}

/***************************************************/

int i199 = 1;

void test199()
{
label:
{
int i199 = 2;
}
assert(i199 == 1);
}

/***************************************************/
// 6690

Expand Down Expand Up @@ -7080,6 +7093,7 @@ int main()
test8360();
test9577();
test6141();
test199();
test8526();
test161();
test8819();
Expand Down

0 comments on commit ced168b

Please sign in to comment.