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

We need to use the 'more specific' relation in type promotion #13866

Closed
johnniwinther opened this issue Oct 7, 2013 · 2 comments
Closed

We need to use the 'more specific' relation in type promotion #13866

johnniwinther opened this issue Oct 7, 2013 · 2 comments
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-obsolete Closed as the reported issue is no longer relevant type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@johnniwinther
Copy link
Member

The current rule for when an is-expression 'shows a type' uses subtyping to ensure that we always promote to a type that holds atleast the same information as the current type (in order to hold all type information through a single type).

This breaks down due the fact that subtyping is not a partial order. For instance:

class A { aMethod() {} }
class B { bMethod() {} }

List<A> list = ...
if (list is List) { // ok since List <: List<A>
  if (list is List<B>) { // ok since List<B> <: List
    list[0].aMethod(); // warning, since operator[] on List<B> returns a B
  }
}

We need to use the more specific relation (<< defined in §15.4) as the criterion for showing the type of an is-expression. In the example this will make the promotion from List<A> to List invalid and thus retain the information that 'list[0]' returns an A.

Currently the more specific relation is not defined on function types and void, so this needs to be added.

I propose that a function type T is more specific that Function, and more specific than another function type S if T is a subtype S, the return type of T is more specific than the return type of S (covariance), and that all parameter types of T are less specific that the corresponding parameter types of S, if any, (contravariance).

For void, I propose that we only have void << void to avoid any promotion that changes the known return type of a function to or from void.

@gbracha
Copy link
Contributor

gbracha commented Oct 7, 2013

Added Accepted label.

@johnniwinther johnniwinther added Type-Defect area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). labels Oct 7, 2013
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed priority-unassigned labels Feb 29, 2016
@lrhn lrhn added the closed-obsolete Closed as the reported issue is no longer relevant label Jun 22, 2018
@lrhn
Copy link
Member

lrhn commented Jun 22, 2018

Since List <: List<A> is no longer true in Dart 2, I believe this is no longer an issue.

@lrhn lrhn closed this as completed Jun 22, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). closed-obsolete Closed as the reported issue is no longer relevant type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants