-
Notifications
You must be signed in to change notification settings - Fork 170
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
Add lint implicit_call_tearoffs #3592
Conversation
In an effort to simplify the language we may consider removing the implicit `call` tearoff which can coerce an instance of any class which defines a `call` method into a `Function` type. Authors should explicitly add the `.call` so there is less magic.
I'm having trouble with this lint. I don't see any of the Testing this locally requires a dependency override on The reason I expect to see an However when the test added in this PR fails and it dumps the AST, I don't see For instance in the test I have the line
I expected this to be
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out that the utility function that dumps the AST in the event of a test failure does a fresh parse of the AST (see https://github.com/dart-lang/sdk/blob/f45353eafd1a28b5b33ff227a5c46c657c0b550c/pkg/analyzer/lib/src/lint/util.dart#L57), so that's why you weren't seeing ImplicitCallReference
nodes in your AST dump.
These don't seem to have an ImplicitCallReference
@bwilkerson - do you expect that an expression like I can see that we check whether to insert an implicit call reference, however the Is it possible there is a bug that is causing some implicit call tearoffs to not be represented? |
I don't know. I think @srawlins added that node, so he's likely to be a better source for answers than I am. |
Hmm I doubt that the |
Most definitely, since it's not used a lot in the wild. |
In what situation would you expect it to be non-null? When I see this method hit in the code I'm parsing I only have seen
I had assumed that you did account for |
I would expect it to be non-null for something like the AsExpression here: T f(Callable callable) => callable as Function; I think the contextType there should be T (like I had assumed that you did account for as Function base on the handling of implicit call references in visitAsExpession. Can you help me understand the intent of that call if we aren't accounting for as Function with implicit call references? No they're just sort of accounted for in most expressions. I'm not sure the list, but for example in this test case we rewrite There are more tests below that which show which expressions we'll rewrite as an implicit call tear-off. I actually can't get a similar test for an AsExpression to generate an ImplicitCallReference node; it might be because inference is never used when computing the static type of an as-expression (the static type is just always the right side if the as-expression). |
Ah, I see now that |
@pq - this lint is ready for review. |
@natebosch – we should add this to lints/core.yaml – right? Do we have an issue open to track that? |
Yes
dart-lang/language#2399 tracks the language change. I noted there that we'll also want to include this line in the core set. |
@pq - do you have an opinion on whether this should be named |
I don't feel super strongly to be honest but we've been trending away from prefixes like |
+1 to not using "avoid". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great. Could we rename it to implicit_call_tearoffs
(plural)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's great. Love the tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. Thanks!
In an effort to simplify the language we will consider removing the implicit `call` tearoff which can coerce an instance of any class which defines a `call` method into a `Function` type. Authors should explicitly add the `.call` so there is less magic.
In an effort to simplify the language we may consider removing the
implicit
call
tearoff which can coerce an instance of any class whichdefines a
call
method into aFunction
type. Authors shouldexplicitly add the
.call
so there is less magic.