Skip to content

Teach the VarDeclUsageChecker About Variables Bound in Patterns #33033

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

Merged
merged 1 commit into from
Jul 21, 2020

Conversation

CodaFi
Copy link
Contributor

@CodaFi CodaFi commented Jul 21, 2020

The VDUC was missing a class of AST nodes that can bind variables:
patterns (in switch statements). For these, it was falling back to
requesting a simple replacement of the bound variable name with _. But
for patterns, this means there's a two-step dance the user has to go
through where the first fixit does this:

.pattern(let x) -> .pattern(let _)

Then a second round of compilation would emit a fixit to do this:

.pattern(let _) -> .pattern(_)

Instead, detect "simple" variable bindings - for now, variable patterns
that are immediately preceded by a let or var binding pattern - and
collapse two steps into one.

Resolves rdar://47240768

The VDUC was missing a class of AST nodes that can bind variables:
patterns in switch statements. For these, it was falling back to
requesting a simple replacement of the bound variable name with _. But
for patterns, this means there's a two-step dance the user has to go
through where the first fixit does this:

.pattern(let x) -> .pattern(let _)

Then a second round of compilation would emit a fixit to do this:

.pattern(let _) -> .pattern(_)

Instead, detect "simple" variable bindings - for now, variable patterns
that are immediately preceded by a `let` or `var` binding pattern - and
collapse two steps into one.

Resolves rdar://47240768
@CodaFi
Copy link
Contributor Author

CodaFi commented Jul 21, 2020

@swift-ci smoke test and merge

@swift-ci swift-ci merged commit 0950a2d into swiftlang:master Jul 21, 2020
@CodaFi CodaFi deleted the would-that-it-were-so-simple branch July 22, 2020 02:10
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