-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Summary representation of constants does not reflect the results of type inference #33441
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
Comments
After further searching, I see that #32290 partially overlaps with this issue (it only covers the case of |
OK, so after a lot of digging and an initial implementation, this is not actually an issue. We reresolve constant expressions after resynthesis time, including inference, which was almost the approach I took but decided to reresolve at link time because it could have been a bit more performant. After writing a test and trying to get it to fail without my code, I simply couldn't find a single way:
We thought this would fail because:
But it turns out the reason for this is much much simpler than this bug describes (#35441); |
After further research, it appears that this is indeed still an issue, and it's a special case of a larger problem: the summary representation of constants is purely syntactic, so it does not take into account the results of type inference. I believe the reason @MichaelRFairhurst didn't see an issue is that when a single file is analyzed, type inference is performed prior to constant evaluation, masking the problem. Currently I'm aware of two manifestations of this issue: #35908 and #35993. @scheglov is working on fixing this by representing constants in summaries by their values rather than their syntactic form. I'm repurposing this bug to track his work on this. |
@stereotype441 We have a problem. https://dart-review.googlesource.com/c/sdk/+/93961/ implements storing by value, and this fixes #35908 without a need for the workaround. However #35993 is still a problem, and I don't see how to solve it with this approach. Constructor initializers have to be stored syntactically, because the values they produce into fields and super-constructor-invocations depend on the values of constructor parameters. |
@scheglov Hmm, you're right--that's an unfortunate problem. Brainstorming some possible approaches to the problem:
WDYT? I'm also happy to discuss this in person on Monday. |
Consider the following code:
When summarizing the above file, the analyzer records the static type of the variables
x
,y
, andz
(all of which areObject
), but it does not record the inferred type arguments of their initializer expressions. As a result, if another build target attempts to make use of the summary and access the constant values ofx
,y
, andz
, it will see values of typesC<dynamic>
,List<dynamic>
, andMap<dynamic, dynamic>
, respectively, whereas the correct constant value types areC<int>
,List<int>
, andMap<int, int>
.Fixing this will require expanding the summary format to store additional type inference information.
The text was updated successfully, but these errors were encountered: