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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzer issue with super-bounded type and invariance #35332

Open
eernstg opened this Issue Dec 5, 2018 · 1 comment

Comments

Projects
None yet
2 participants
@eernstg
Member

eernstg commented Dec 5, 2018

Just noted that #34906 was closed and the example program is accepted as it should be. 馃憤

However, the commit a88b10a where this was achieved does not quite handle all variances. Here's a slightly different example:

typedef G<X, Y extends Function(X)> = X Function(Y Function(Y));
class C<Z extends G<num, Function(Object)>> {}

main() {
  C<G<dynamic, Function(Null)>> target; // Should be reported as an error.
}

A fresh analyzer (commit 1ca3f3d, which correctly accepts the example in #34906) fails to report an error for this example, even though it should. (Similarly, no error is reported by a fresh vm, same commit, but the error is reported by dartk in a non-landed CL where 80140 is being implemented, so that's being handled, and hence I'll just use area-analyzer in this issue.)

The point is that C<G<dynamic, Function(Null)>> is not well-bounded, and this is a compile-time error (as specified here): C<G<dynamic, Function(Null)>> is only well-bounded if it is regular-bounded or super-bounded. It's easy to see that it is not regular-bounded (G<dynamic, Function(Null)> is not a subtype of G<num, Function(Object)>, e.g., dynamic is not a subtype of num).

In order to be super-bounded, we need to perform some "extreme substitutions" (replacing certain occurrences of a top type by Null and vice versa, according to the variance), which yields C<G<Null, Function(Null)>> (note that Null is not replaced by Object because it occurs in an invariant position in G<..., Function(Null)>, because Y of G is invariant). The result of these substitutions must then be regular-bounded. But C<G<Null, Function(Null)>> is not regular-bounded, because G<Null, Function(Null)> is not a subtype of G<num, Function(Object)>.

So we have a compile-time error, and it is not reported.

PS: The spec update CL 80140 is in the pipeline, and it is concerned with super-bounded types, but the issue reported here exists independently of CL 80140, so this issue is not blocked on the outcome for that CL.

@stereotype441

This comment has been minimized.

Member

stereotype441 commented Dec 5, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment