Skip to content

Fix position context of enum/decl literal in if/while/for#2342

Merged
Techatrix merged 4 commits into
zigtools:masterfrom
FnControlOption:if
Jun 5, 2025
Merged

Fix position context of enum/decl literal in if/while/for#2342
Techatrix merged 4 commits into
zigtools:masterfrom
FnControlOption:if

Conversation

@FnControlOption

Copy link
Copy Markdown
Contributor

For example:

var foo = if (bar) .foo else .bar;
//                 ^^^^

@Techatrix Techatrix left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This needs to handle for and while loops as well.

@FnControlOption

Copy link
Copy Markdown
Contributor Author

Hm… Do you have any example code of loops that have only a decl literal as the body? I know it’s possible to have a break statement with a decl literal, but we already support that 🤔

@Techatrix

Copy link
Copy Markdown
Member

Do you have any example code of loops that have only a decl literal as the body?

None that is semantically valid but that doesn't matter regarding the position context. The token sequence if (expr) . should produce the same position context as while (expr) .. This should also prevent nonsensical code completions like this:

const foo: ?u32 = undefined;
const bar = while (foo) .<request completions here>

@FnControlOption FnControlOption marked this pull request as draft June 5, 2025 13:56
@FnControlOption FnControlOption changed the title Fix position context of enum/decl literal in if statement Fix position context of enum/decl literal in if/while/for Jun 5, 2025
@FnControlOption FnControlOption marked this pull request as ready for review June 5, 2025 15:08
@Techatrix Techatrix merged commit 3b9aa69 into zigtools:master Jun 5, 2025
6 checks passed
@FnControlOption FnControlOption deleted the if branch June 7, 2025 15:23
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.

2 participants