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

Implement type alias parameter variance for super-bounded types #33444

Open
2 tasks
eernstg opened this issue Jun 14, 2018 · 1 comment
Open
2 tasks

Implement type alias parameter variance for super-bounded types #33444

eernstg opened this issue Jun 14, 2018 · 1 comment
Labels
area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...).

Comments

@eernstg
Copy link
Member

eernstg commented Jun 14, 2018

As of commit bfa8be8, and following up on the discussion in #33261, each parameter in a parameterized type alias has an associated inferred variance (which classifies that parameter as covariant, contravariant, invariant, or neither of those).

The variance of a type alias parameter is used in the determination of whether any given type is super-bounded, in that only a covariant parameter occurs covariantly in a parameterized type based on that type alias (so T occurs covariantly in G<T> when the type parameter of G is covariant, and T occurs covariantly in G<int Function(T)> when the type parameter of G is contravariant, etc), and similarly for occurring contravariantly and invariantly.

For example:

// The type parameter X of Fco is covariant because it is used in a
// covariant position, and only that, in the type on the right hand side.
typedef Fco<X extends int> = X Function();

// The type parameter X of Fct is contravariant because it is used in a
// contravariant position, only, in the type on the right hand side.
typedef Fct<X extends int> = void Function(X);

// The type parameters X of Fin1 and Fin2 are invariant because they are used
// in an invariant respectively both a covariant and a contravariant position
// in the type on the right hand side.
typedef Fin1<X extends int> = void Function<Y extends X>();
typedef Fin2<X extends int> = X Function(X);

// The type parameter X of F has no variance. Super-bounding is pointless,
// and not supported.
typedef F<X extends int> = void Function();

main() {
  // Correctly super-bounded, because `Fco<Null>` is regular-bounded.
  Fco<dynamic> v1; //# 01: ok
  // Not correctly super-bounded, because `Fct<dynamic>` is not regular-bounded.
  Fct<dynamic> v2; //# 02: compile-time error
  Fct<Null> v2b; // Regular-bounded (no need to consider substitutions).
  // Not correctly super-bounded, because `Fin1<dynamic>` is not regular-bounded.
  Fin1<dynamic> v3; //# 03: compile-time error
  Fin1<Null> v3b; // Regular-bounded.
  // Not correctly super-bounded, because `Fin2<dynamic>` is not regular-bounded.
  Fin2<dynamic> v4; //# 04: compile-time error
  Fin2<Null> v4b; // Regular-bounded.
  // Not correctly super-bounded, because `F<dynamic>` is not regular-bounded.
  F<dynamic> v5; //# 05: compile-time error
  F<Null> v5b; // Regular-bounded.
}

This issue is concerned with the implementation of support for this behavior, and in particular for detecting this kind of compile-time error.


Subtasks

@eernstg eernstg added area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). area-multi labels Jun 14, 2018
@munificent munificent added area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). and removed area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). area-multi labels Jun 22, 2018
@a-siva a-siva added the area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). label Jul 9, 2018
@munificent munificent removed the area-language Dart language related items (some items might be better tracked at github.com/dart-lang/language). label Jul 11, 2018
@srawlins
Copy link
Member

Analyzer definitely does not report errors at all of the compile-time error spots, and reports some errors on other lines. :/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...).
Projects
None yet
Development

No branches or pull requests

4 participants