Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 199 - Label causes scope to collapse into parent #3024

Merged
merged 1 commit into from Dec 28, 2013

Conversation

yebblies
Copy link
Member

Do what C does - introduce a scope.

https://d.puremagic.com/issues/show_bug.cgi?id=199

@monarchdodra
Copy link
Contributor

The issue "seems" that it is now always creating a scope after a label. The failure can be reduced to:

void main()
{
    Lcontinue: size_t curallocsize = void;
    curallocsize = 1; //Error: undefined identifier curallocsize
}

Maybe this will spontaneously fix after if you solve 10199 first?

In any case, I can't wait for this to get fixed. It's been one of my oldest standing issues with the language :)

@yebblies
Copy link
Member Author

Forgot to push after I fixed it!

@monarchdodra
Copy link
Contributor

This is failing on test 4448, but I think the test is wrong:

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

L1 labels a block. Regardless of whether or not said block is scoped, it is not labeling the switch. It is albelling a block which (currently) is not creating a scope. The switch not being labelled, the break L1; is (I think) currently an accepts invalid either way.

This fix also fixes that. The test should be moved to fail_compilation.

@yebblies
Copy link
Member Author

I agree.

@@ -2738,7 +2738,8 @@ static assert({ E8365[2][2][2] x; return x[0][0][0]; }() == E8365.first);
int bug4448()
{
int n=2;
L1:{ switch(n)
{ switch(n)
L1:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised this compiles. What does it do? It's a switch that contains a labeled body? Does the grammar allow this?

It's the switch that should be labeled:

    int n=2;
    {
        L1: switch(n)
        {
            ...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't compile. I've wrapped it in a do-while, the test case seemed to intentionally not label the switch.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although, it is legal for a switch to have a LabelStatement as its body.

@WalterBright
Copy link
Member

Need corresponding doc pull.

@yebblies
Copy link
Member Author

How do I document this? The old behavior was undocumented... "A label on a statement doesn't do anything weird to the scope" ???

@yebblies
Copy link
Member Author

dlang/dlang.org#457

@yebblies
Copy link
Member Author

@WalterBright ping

WalterBright added a commit that referenced this pull request Dec 28, 2013
Issue 199 - Label causes scope to collapse into parent
@WalterBright WalterBright merged commit ced168b into dlang:master Dec 28, 2013
@yebblies yebblies deleted the issue199 branch December 28, 2013 09:06
@yebblies
Copy link
Member Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants