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

Translate break and continue with label #15

Open
paulirwin opened this issue Jun 29, 2021 · 2 comments
Open

Translate break and continue with label #15

paulirwin opened this issue Jun 29, 2021 · 2 comments

Comments

@paulirwin
Copy link
Owner

Currently one of the biggest headaches I've run into is that break and continue with label aren't translated, and the resulting code is likely incorrect as you would usually only use a label if you wanted to break/continue an outer loop, not the inner-most one. I'm wondering if we could translate break and continue with label to use goto, perhaps. I believe this should work, but let me know your thoughts:

Break-with-label input:

label_1:
while (true) {
    while (true) {
        break label_1;
    }
}

Break-with-label proposed output:

label_1:
while (true) {
    while (true) {
        goto label_1_break;
    }
}
label_1_break: ;

Continue-with-label input:

label_1:
while (true) {
    while (true) {
        continue label_1;
    }
}

Continue-with-label proposed output:

label_1:
while (true) {
    while (true) {
        goto label_1_continue;
    }
    label_1_continue: ;
}

I just did a quick test and it seems to work but I'm worried that I'm missing something. The semicolon after the C# labels are needed to make it a valid label target but they're basically a noop for jumping purposes.

@willibrandon
Copy link
Contributor

Interesting. I wasn't aware of labeled breaks/continues in Java.

I am seeing a number of csharplang proposals which would add some type of support for labeled breaks/continues in C# but none of which have moved passed the proposed stage. Seems to be a controversial topic.

Do you mind sharing how you have translated the labeled breaks/continues to goto?

@paulirwin
Copy link
Owner Author

My translation was by hand, an example of how we could accomplish it.

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

No branches or pull requests

2 participants