Skip to content

A super-bounded type can be given as an actual type argument in a function call #33815

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

Open
eernstg opened this issue Jul 11, 2018 · 0 comments
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec P4 type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Milestone

Comments

@eernstg
Copy link
Member

eernstg commented Jul 11, 2018

Consider the following program (variant of example given in #33805):

class A<X extends A<X>> {}

X testme<X>() { print(X); return null; }

main() {
  A a1 = testme<A<dynamic>>();
  A a2 = testme<A<A<dynamic>>>();
  A a3 = testme();
}

The response from dartanalyzer looks as follows:

$ dartanalyzer --preview-dart-2 --no-hints n003.dart
Analyzing n003.dart...
  error • 'dynamic' doesn't extend 'A' at n003.dart:8:19 • type_argument_not_matching_bounds
  error • 'A' doesn't extend 'A<A>' at n003.dart:9:19 • type_argument_not_matching_bounds
  error • 'dynamic' doesn't extend 'A' at n003.dart:9:21 • type_argument_not_matching_bounds
3 errors found.
$ dartanalyzer --version
dartanalyzer version 2.0.0-dev.68.0

In the first line of main, we are passing the type argument A<dynamic> to the invocation of testme, and that is in itself a super-bounded type (because A<Null> is regular-bounded, because Null <: A<Null>). For testme there are no constraints on the type argument, and in particular it can be a super-bounded type. So the analyzer should allow this.

The second line of main is similar, but it illustrates that the analyzer flags an error both for the type argument A<A<dynamic>> as a whole, and for the nested type argument A<dynamic>. So none of them are allowed to be a super-bounded type, and they should both be allowed.

With the common front end, the third line gets the inferred type argument A<A<dynamic>> (the same as in the second line), which can be detected by running the program with the VM, due to print(X). With dartanalyzer it is not obvious what the inferred type argument is, but we do not get an error from there.

@eernstg eernstg added legacy-area-analyzer Use area-devexp instead. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jul 11, 2018
@bwilkerson bwilkerson added this to the Dart2.1 milestone Aug 28, 2018
@devoncarew devoncarew modified the milestones: Dart2.1, PostDart2.1 Sep 5, 2018
@aadilmaan aadilmaan modified the milestones: Future, D25 Release Jun 4, 2019
@srawlins srawlins added the dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec label Jun 17, 2020
@srawlins srawlins added the P3 A lower priority bug or feature request label Dec 15, 2021
@srawlins srawlins added P4 and removed P3 A lower priority bug or feature request labels May 5, 2023
@bwilkerson bwilkerson added area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. and removed legacy-area-analyzer Use area-devexp instead. labels Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-dart-model For issues related to conformance to the language spec in the parser, compilers or the CLI analyzer. dart-model-analyzer-spec Issues with the analyzer's implementation of the language spec P4 type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants