[SR-13706] Fix-it for missing let/var in pattern when identifier is unbound #56103
Labels
compiler
The Swift compiler in itself
diagnostics QoI
Bug: Diagnostics Quality of Implementation
improvement
type checker
Area → compiler: Semantic analysis
Additional Detail from JIRA
md5: 7687cfd33e3fca67b424828244e645ce
relates to:
Issue Description:
The problem with this code:
is that the programmer forgot to write `case let` or `case var` to introduce a new binding in the pattern for Cons. Because of this, the compiler interpreted it as an expression pattern and reports:
I think it would be helpful to have a fix-it suggesting that they add a let / var, since no `hd` exists in the scope.
In some situations, this fix-it should not be emitted, such as:
where a suggestion to add 'let' or 'var' for the second sub-pattern in the tuple will introduce an invalid redeclaration of 'a'. In this next situation, a different fix-it would be better for the two unbound identifiers:
Based on the type of the switch's scrutinee and the patterns themselves, a better fix-it would be to suggest adding a dot in front of `none` and `gray`. This way, they'll refer to their respective enums (Optional<T> and Color) because their names match one of the enums variants exactly. The better fix-it is most likely what the programmer intended instead of introducing a new binding.
The text was updated successfully, but these errors were encountered: