Sdk: Analyzer throws compile error if one of parameter bound is set to Null

Created on 9 Oct 2018  路  6Comments  路  Source: dart-lang/sdk

Dart SDK Version: 2.1.0-dev.6.0
OS: Windows 10

The following example declares class A<String, X extends A<Null, A<String,X>>> and prints its actual type:

class A<String, X extends A<Null, A<String,X>>> {}
main() { print(A); }

Dart passes with this and in runtime A's actual type is A<dynamic, A<Null, A<dynamic, dynamic>>>.

Dartanalyzer throws compile error here:

error - 'A' doesn't extend 'A>>' at test.dart:1:35 - type_argument_not_matching_bounds

Seems like analyzer behavior is incorrect and analyzer should pass here.

area-analyzer type-bug

All 6 comments

There is a similar situation with A<String, X extends A<void, A<String,X>>>: it fails with analyzer and passes with dart as well.

Another question is - what should be a correct runtime type of A here?
Dart returns A<dynamic, A<Null, A<dynamic, dynamic>>>, but should not it beA>>` instead?

I think it's confusing that String is the name of a type variable, couldn't it be renamed to something more comprehensible like Y? Otherwise dart seems to get it right. For dartanalyzer it would be useful to check whether this issue is overlapping with other issues reporting problems with type_argument_not_matching_bounds (or maybe even a duplicate).

Oh sorry, it's my misprint.
But still

class A<X1 extends String, X extends A<Null, A<String,X>>> {}
main() { print(A); }

passes with dart and throws compile error with analyzer:

error - 'A' doesn't extend 'A>>' at test.dart:1:46 - type_argument_not_matching_bounds

OK! ;-)

Possibly related: #33991

Just noted that this one got misplaced (possibly because the code was corrected after I added the label area-analyzer, and I didn't notice that the resulting code demonstrated a problem with the front end). In any case, the problem doesn't exist today.

Cf. this comment, we have this code:

class A<X1 extends String, X extends A<Null, A<String,X>>> {}
main() { print(A); }

We get this response from dart (of ee8d9d2fd357c62a69428fd384f58ca89ca12bc2):

> dart n052.dart
n052.dart:1:28: Error: Type argument 'A<String, X>' doesn't conform to the bound 'A<Null, A<String, X>>' of the type variable 'X' on 'A'.
 - 'A' is from 'n052.dart'.
Try changing type arguments so that they conform to the bounds.
class A<X1 extends String, X extends A<Null, A<String,X>>> {}
                           ^
n052.dart:1:28: Context: This is the type variable whose bound isn't conformed to.
class A<X1 extends String, X extends A<Null, A<String,X>>> {}
                           ^

This is a correct detection of a bounds violation: it is indeed true that A<String, X> is not a subtype of A<Null, A<String, A<String, X>>>, so A<Null, A<String, X>> is not regular-bounded; and it is also not a super-bounded type because the associated substitution does nothing.

So we do get the error from the front and that we should have. The analyzer (from same commit) responds as follows:

> dartanalyzer n052.dart
ERROR|COMPILE_TIME_ERROR|TYPE_ARGUMENT_NOT_MATCHING_BOUNDS|/usr/local/google/home/eernst/lang/dart/scratch/201911/n052.dart|1|46|11|'A<String, X>' doesn't extend 'A<Null, A<String, A<String, X>>>'.

Again, the error is correct.

So I'll close this issue.

Was this page helpful?
0 / 5 - 0 ratings