-
Notifications
You must be signed in to change notification settings - Fork 26
make least upper bound more useful #288
Comments
Note: we're using the analyzer's LUB computation, which follows the spec. It's not the ideal for generic types. @stereotype441, @leafpetersen - do you know which section of the spec deals with LUB of generic types? 19.8.2 primarily deals with function types. |
Section 19.8.2 is the complete definition of LUB. It only looks like it On Fri, 14 Aug 2015 at 11:02 vsmenon [email protected] wrote:
|
I believe it's all basically section 19.8.2. The function type discussion is just the last part of that section - the first part deals with interface types (and hence implicitly generics). Consider:
What's the lub of It doesn't really have the expected properties of a least upper bound with respect to the subtyping relation, so it doesn't work very well for generics where the subtyping relation is richer than the super-interface relation (the set of super-types of |
@leafpetersen the implementation in analyzer assumes that the statement "The least upper bound relation is symmetric and reflexive." (from the third paragraph of 19.8.2) takes precedence over the rest of 19.8.2. So analyzer would say that the lub of A and A is A. I agree with your larger point, though (that it doesn't have the expected behavior when generics are involved, because it is defined in terms of super-interfaces rather than super-types). |
Edited my comment to add quotes around the generic parameters that otherwise disappear in markdown - @stereotype441 , I think that addresses your comment (please follow up again if not). |
@leafpetersen Yes, that addresses my comment. Thanks. |
The terminology is somewhat confusing, given that it is not a least upper bound at all --- in case of a subtype graph where a least upper bound does not exist (A <: I,J and B <: I,J) we just proceed to the next level (if I <: K and J <: K it would be K) until there is no ambiguity. But it is an upper bound, and there is an algorithm, so we could call it "the standard upper bound". We could also argue that it is OK to take some upper bound which is not least, because the "leastness" is never crucial for the static analysis, nor for the runtime semantics. However, the result is not pretty with cases like |
@eernstg Yes, there are two issues: one is that it is not a least upper bound, but the other is that it is not defined on the subtype graph at all, but rather on the super-interface graph (and hence doesn't consider candidates that are super-types but not super-interfaces). I actually think it is the latter issue that we are more concerned with here. |
OK. I think that the two topics are very tightly coupled, though, because On Fri, Aug 14, 2015 at 9:31 PM, Leaf Petersen [email protected]
Erik Ernst - Google Danmark ApS |
Fair point. It seems to me that an equally significant issue with respect to the "leastness" though is that least upper bounds (in the usual sense) don't always exist absent the addition of intersection types for the reasons you mention above (e.g. class A and B both extend I and implement J, so both I and J are upper bounds for A and B, but neither dominates the other). @eernstg Do you know off the top of your head what other languages with similar subtype hierarchies do? |
It's not a perfect match, but On Mon, Aug 17, 2015 at 6:13 PM, Leaf Petersen [email protected]
Erik Ernst - Google Danmark ApS |
moved to dart-lang/sdk#25248 |
actually merged into dart-lang/sdk#25821 |
consider:
This
l
is inferred asEfficientLength
The text was updated successfully, but these errors were encountered: