This repository has been archived by the owner on Nov 20, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fix false positives in prefer_collection_literals #2340
Fix false positives in prefer_collection_literals #2340
Changes from all commits
691ec93
49cb6f1
9222e13
b9a7202
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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 might be completely misunderstanding what this method is trying to accomplish, but it looks like it's trying to find the type that's required by the context in which the
InstanceCreationExpression
appears. If so, then I think what we really need here is the algorithm implemented by the_ContextTypeVisitor
in theanalysis_server
package, which is both more complete and more correct.If I'm not understanding the purpose of this method then my comments below are probably also wrong.
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.
yes, that's exactly the goal. Is there a reasonable way we could expose that functionality here?
Specifically, the problem this was attempting to solve is that in some places if we don't specifically use
LinkedHashMap
over{}
then we'll get some other analysis error. We want to suppress the lint in only those places where honoring the lint would cause a static error.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 suspect that we should just add a TODO and tackle that later. It will require moving the
_ContextTypeVisitor
to theanalyzer
package and exposing an API through which it can be used. That's a bigger task than I'm asking you to tackle here.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 doesn't look right either. I believe that the static type of a
NamedExpression
is the static type of the expression being named (which is the instance creation expression). I suspect that you needparent.staticParameterElement?.type
in order to get the type of the parameter associated with the argument.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 also looks wrong.
parent.expression
will always return the instance creation expression from which we started. I think what you want to do here is recurse to see whether you can find a type that would be inferred as the return type of the closure (assuming that this is the body of a closure).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 is another existing bug with false negatives.
Is this something you might be able to work on? I can easily add some test cases showing the problem but I'm having a hard time figuring out the right things to look for in the analyzer APIs.
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.
If you can send me the test case(s), I'll be happy to at least look at what it would take to implement them.
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.
https://github.com/dart-lang/linter/pull/3705/files adds a line in the test data library that should have a lint but doesn't due to this bug.
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 also looks wrong. If the instance creation is the right operand then you want the type of the parameter. If it's the left operand then there is no context type.