-
Notifications
You must be signed in to change notification settings - Fork 224
Simple definite assignment #1000
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
Conversation
variable which is ascribed no **initialization inferred types** on any path | ||
shall be treated as having declared type `Never`. Note that despite the | ||
requirement that the **initialization inferred types** be equal at join points, | ||
it is possible for a variable to take on different **initialization inferred |
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.
We could alternatively specify it to be an error if a variable ever takes on different initialization inferred types.
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 would still allow a single type to be used, but anything with subtypes needs to be declared. Initializing to 0
and 1.0
would be invalid, not null
(and avoid the LUB).
If you initialize with two different Widget subclasses, you need to say Widget on the variable.
It does mean that var x; if (test) { x = e1; } else {x = e2;}
doesn't work like var x = test ? e1 : e2;
, but there are so many ways it can not do that, and I'm not particularly fond of our LUB to begin with.
It could probably work. And it's a safe initial behavior, we can always improve later if we make it an error now.
``` | ||
|
||
Local variables with no explicitly written type but with an initializer are | ||
given an inferred declared type equal to the type of their initializer. In the |
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.
Is this "inferred declared type" considered a "type of interest"?
From the description of initializing assignment, where we say that it is "treated ... as declared with the assigned expression as its initializing expression", and then we say that it is a type of interest, it seems that the answer is "yes". But I'd like to know for sure.
At a join point in the program, if an **untyped variable** has been given an | ||
**initialization inferred type** on more than one of the reachable paths to the | ||
join point and all of such **initialization inferred types** are syntactically | ||
equal, the variable is treated after the join point as having that |
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.
Syntactically equal before or after normalizaion?
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 prefer this model over the previous one, appreciating the simplification for developers that follows from the "no LUB" decision.
They will now be able to look up any of the the initializing assignments and trust that this is the source of the pseudo-declared type of the variable, rather than needing to look up all of them and computing a LUB (which is tricky in its own right) for all the join points.
Agree. Let's do this. |
Closing this, we took a different approach. |
This is an alternative approach to definite assignment based promotion derived as a simplification of the definite assignment promotion proposal here. It eliminates the use of upper bound at join points, thereby enforcing the property that an untyped variable is never assigned more than one inferred type, except on paths that never join.