sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Analyzer produces unexpected compile time error when checks instantiate to bounds for nonfunction typedef.

Open iarkh opened this issue 4 years ago • 4 comments

Dart SDK version: 2.13.0-59.0.dev (dev) (Sun Feb 21 18:06:58 2021 -0800) on "windows_x64"

Here is a source code example:

typedef F<X> = void Function<Y extends X>();
F<X> toF<X>(X x) => <Y extends X>() {};

class A<X> {}
class B<X> extends A<X> {}
class C<X1, X2, X3, X4> {}

typedef G<X1 extends A<X1>, X2 extends A<X1>, X3 extends B, X4 extends X2> =
    C<X1, X2, X3, X4>;

test(G source) {
  var fsource = toF(source);
  F<G<dynamic, A<A<dynamic>>, B<dynamic>, A<A<dynamic>>>> target1 = fsource;
}

main() {}

Sample output is:

$> dartanalyzer --enable-experiment=nonfunction-type-aliases test.dart
Analyzing test.dart...
  error - 'A<A<Never>>' doesn't conform to the bound 'A<Never>' of the type parameter 'X2'. - test.dart:13:16 - type_argument_not_matching_bounds
  error - A value of type 'void Function<Y extends C<A<dynamic>, A<A<dynamic>>, B<dynamic>, A<A<dynamic>>>>()' can't be assigned to a variable of type 'void Function<Y extends C<dynamic, A<A<dynamic>>, B<dynamic>, A<A<dynamic>>>>()'. - test.dart:13:69 - invalid_assignment
  hint - The value of the local variable 'target1' isn't used. - test.dart:13:59 - unused_local_variable
2 errors and 1 hint found.

It looks rather strange: as it's nonfunction typedef, Never should not appear in the type parameter here.

It's affects co19 test LanguageFeatures/Instantiate-to-bound/nonfunction_typedef/static/nonfunction_l4_t01.dart

iarkh avatar Feb 25 '21 16:02 iarkh