-
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] Expression.staticParameterElement returns synthetic elements for generic functions #54669
Comments
While I can see how it seems odd that you're getting a synthetic element, I'm not sure what problem that's causing you (so I don't know whether there's a work-around that I can point you to). Is there information you need that the synthetic member doesn't have, or is there some reason why you think you need the non-synthetic element? |
My use case is getting metadata for a e.g I want to get the const foo = Object();
void test<@foo T>(T arg) { ... }
void main() {
test(1); // <== Here
} The issue arises because the (synthetic) element returned by |
The synthetic elements appear to come from // ...
} else {
// getFreshTypeParameters creates synthetic copies of the type parameter elements, but does not copy over metadata.
rawType = getFreshTypeParameters(rawType.typeFormals)
// applyToFunctionType creates synthetic parameter elements
// (via ParameterElementExtensions.copyWith) with the new synthetic type parameters (even if the parameter does
// not use the type parameter)
.applyToFunctionType(rawType);
// ... The synthetic |
It'd also be helpful for |
Thanks for the use cases. Unfortunately, I can't think of any easy, clean work-arounds that are currently available. Do the synthetic parameter elements have enough information to be able to get back to the |
I don't think so. Interestingly the synthetic type parameters are not marked as synthetic, even though their offset is set to |
I'll try working on a fix, but I'm not sure if it will fit in with the code style of the rest of the codebase. |
Thanks! It might be beneficial (as in save you some time and effort) to start with a short design proposal that we can look at to see whether the direction you're thinking of would be acceptable. @scheglov For additional pointers. |
It turns out Figuring that out was relatively quick. Going through and updating all the tests for other behaviour that were written expecting the parameter members to be synthetic is taking longer :) The change itself is only 3 lines, so I'll just upload it directly. If it doesn't work, I won't actually have wasted that much time. |
It was quite long time since I touched the inference code, so I probably know as much about it as anyone else. One complication with using non-synthetic I for long time consider using |
I did notice summaries might be an issue (anywhere that uses getFreshTypeParameters is, really) but I haven't worked with them at all so I wouldn't know where this could be an issue. |
Fixed in 7ad5a57 |
Simiarly to #48500,
Expression.staticParameterElement
will return a syntheticParameterMember
when the expression is an argument to a generic function or method. There doesn't seem to be an obvious way to find the actualParameterElement
in the element tree from the syntheticParameterMember
(ParameterMember.declaration
is aParameterElement
, but is also synthetic and has no parent).This applies to:
Dart version:
3.4.0-24.0.dev
Analyzer version:
6.3.0
The text was updated successfully, but these errors were encountered: