Skip to content
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

Expression.staticParameterElement sometimes points to a synthetic element #48500

Closed
stereotype441 opened this issue Mar 3, 2022 · 4 comments
Closed
Assignees
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request

Comments

@stereotype441
Copy link
Member

In the following situations, Expression.staticParameterElement points to a synthetic element that's not in the element tree (i.e. it has an enclosingElement that is null), whereas I believe it would be possible for it to point to a ParameterMember that in turn points to a parameter element in the element tree:

  • In an instance creation expression, when the class being constructed is generic and the type parameters are inferred.
  • In a method call, when the method being called is generic and the type parameters are either explicit or inferred.

I will shortly land some analyzer unit tests that illustrate this.

@stereotype441 stereotype441 added the area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. label Mar 3, 2022
@stereotype441
Copy link
Member Author

I'm hopeful that this issue will be fixed by a refactor I'm currently in the middle of, so I'm going to assign it to myself for now. If I can't manage to fix it as part of the refactor I'll unassign myself.

@stereotype441 stereotype441 self-assigned this Mar 3, 2022
copybara-service bot pushed a commit that referenced this issue Mar 3, 2022
Bug: #48500
Change-Id: I237e44d33cca1d2fe63c205e8bd3dcd775bf079f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/235062
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Paul Berry <[email protected]>
@scheglov scheglov added the P3 A lower priority bug or feature request label Mar 4, 2022
copybara-service bot pushed a commit that referenced this issue Mar 6, 2022
Moves all of the analyzer's type inference logic for invocations into
a single `resolveInvocation` method, defined on an abstract base class
`InvocationInferrer`.  There are concrete derived classes to
specialize this logic for all of the types of AST nodes require this
sort of inference (Annotation, ExtensionOverride,
FunctionExpressionInvocation, InstanceCreationExpression,
MethodInvocation, RedirectingConstructorInvocation, and
SuperConstructorInvocation), and the special logic for each node type
is slotted into the core algorithm using virtual dispatch.

In addition to making the code more maintainable by reducing code
duplication, this change paves the way toward modifying the core
algorithm to allow inference information to flow between arguments in
a generic function call
(dart-lang/language#731).

Also partially addresses #48500 (Expression.staticParameterElement
sometimes points to a synthetic element).

Change-Id: I82788d58a62b6555589da16163317b6bbddd53c1
Bug: dart-lang/language#731, #48500
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/234864
Reviewed-by: Konstantin Shcheglov <[email protected]>
Commit-Queue: Paul Berry <[email protected]>
@abitofevrything
Copy link
Contributor

I believe this needs reopening, as I am encountering this issue again on the latest analyzer version (6.3.0 when I'm writing this):

void genericFunction<T>(T bar) {}

void foo() {
  genericFunction(1); // IntegerLiteral.staticParameterElement is a `ParameterMember` that points to a synthetic `ParameterElement`
}

It still works as expected for generic classes and members though:

class C<T> {
  C(T bar);
}

void foo() {
  C(1); // IntegerLiteral.staticParameterElement is not synthetic
}
abstract class C {
  T method<T>({arg});
}

test(C c) => c.method<bool>(arg: true);  // NamedExpression.staticParameterElement is not synthetic

Hopefully this is just a case that was missed in f5af2d9 that can be quickly changed :)

@parlough
Copy link
Member

@abitofevrything Would you mind opening a new issue with this information? A lot has changed in the analyzer since this was implemented and a new issue would allow your issue to be focused on in isolation. Thanks :)

@abitofevrything
Copy link
Contributor

Created #54669.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request
Projects
None yet
Development

No branches or pull requests

4 participants