Skip to content

fix references and rename of loop labels - #3303

Open
jayhemnani9910 wants to merge 1 commit into
zigtools:masterfrom
jayhemnani9910:fix-loop-label-references
Open

jayhemnani9910 wants to merge 1 commit into
zigtools:masterfrom
jayhemnani9910:fix-loop-label-references

Conversation

@jayhemnani9910

Copy link
Copy Markdown

Renaming a for/while label has two problems:

  • With the cursor on the label declaration (outer: for ...), references, rename and highlight return nothing. Block and switch labels work. Loop labels are declared in the loop body's scope, which starts after the label, and label: inline for was not seen as a label declaration at all.
  • References stop at the end of the loop body, so a break :label in the loop's else branch is left out. Renaming from the body then leaves code that does not compile:
const r = loop: while (i != 3) : (i += 1) {
    if (i == 5) break :loop i;   // rename here
} else {
    break :loop 9;               // error: label not found: 'loop'
};

lookupLabel now falls back to the label declaration at the cursor, inline after label: is a label declaration, and label references scan to the end of the whole loop.

Added cases to the label references test (for with else, while with continue expression and else, inline for) and to the label decl position context test; they fail before the change. zig build test passes (582 passed, 11 skipped).

Loop labels could not be renamed from their declaration (also not on inline
loops), and a break in the loop's else branch was left out, so renaming from
the body broke the code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant