-
Notifications
You must be signed in to change notification settings - Fork 214
[Wildcard Variables][spec] Late, wildcarded variables #3798
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
Comments
Minimum a warning. It's dead code. Same for any other Personally, I'd warn about every local variable named |
Right, it's a straightforward way to provide a context type. However, it could also be useful with some switches which are more conveniently expressed as switch expressions (for the syntax, or in order to enforce exhaustiveness). |
If you want a switch expression Also, don't do that for brevity. If it's for exhaustiveness, we really should consider allowing |
OK, but if local variables that aren't formal parameters are so bad then perhaps just drop the support for such variables being wildcards? |
I'd be fine with that. It's consistent to make If we introduce a warning for If we can get the first warning out soon, I'd be fine with completely disallowing local variable declarations named The only worry is that it's inconsistent with patterns, where we allow you to write var _ = e; // disallowed!
var (_) = e; // allowed?
var (_, x) = (42, e); // pretty much necessary. The I'd warn about both, if the analyzer is up for it. Both are introducing unused local variable declarations, even if they are no longer introducing unused local variables. (A |
In #3820 it is argued that we should allow wildcarded late variable declarations, and leave it to lints and warnings to inform the developer that they are useless (an initializer is dead code, the memory is unused). |
Sounds like we'll probably let the analyzer warn on late wildcard variables. No changes needed for the spec. Closing for now. If we need more discussion on this, feel free to reopen. |
@sgrekhov, do we need to revisit some co19 tests involving late wildcards? |
Yes, we need! I'll do it |
We could make it an error, or we could lint it, but an initializing expression in a
late
variable declaration should presumably be recognized as dead code if the variable is wildcarded (that is, it is local and has the name_
):Similarly, a wildcarded
late
variable with no initializing expression can not be evaluated, and it can not have a new value assigned. So the variable itself would be "dead memory". Error? Lint? OK?Perhaps we should just say that it is an error for a
late
variable to be wildcarded.The text was updated successfully, but these errors were encountered: