-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Analyzer should reject prefix shadowed by parameter #42620
Comments
@eernstg Will this continue to be the semantics after the spec changes related to prefixes that you mentioned recently in a different context? |
Yes, there are no plans to change the lexical lookup rules. So when |
See also #42493, which also would fix the issue. |
…able. See #42620. Change-Id: Ifd18c939082935390df0c2aa0bd724cf6f76c27c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/153705 Commit-Queue: Paul Berry <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]>
Turning over to Konstantin to improve on my hacky fix |
No much changes to resolution itself, only to the way how we create scopes. But we still use `lookupIdentifier` that is basically the old approach to resolution. This also moves the fix of #42620 to TypeNameResolver. I will continue improving in following CLs. Change-Id: I89bae5afe0a7978aba9fe9bf7c8bf08fb59b1440 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/154920 Commit-Queue: Konstantin Shcheglov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
Reporting |
Consider the following code:
The front end rejects this code with the following error:
The analyzer accepts it, offering only this hint:
It seems that for type analysis, the analyzer is considering the
a
ina.Future
to refer to the import ofdart:async
, but for determining whether the import is used, it's considering it to refer to thea
parameter off
.The spec seems pretty clearly in agreement with the front end. In the section "Static Types", it says:
Note that although the example above is contrived, this bug did arise in a real-world circumstance for me; I was attempting to write a method taking an argument called
path
, in a file that containedimport 'package:path/path.dart' as path
, and inside that method I attempted to declare a variable of typepath.Context
. The analyzer did not flag an error (nor did I realize my own mistake); I didn't see an error until I tried to run the program.The text was updated successfully, but these errors were encountered: