Skip to content

Fasta strong mode inference confused same class extending Base<C> and mixing class extending Base<B> #31656

Closed
@mraleph

Description

@mraleph

The code below is extracted from Flutter codebase with classes renamed for brevity.

abstract class B {
}

class C extends B {
  bool c;
}

abstract class Base<T extends B> {
  T get f => null;
}

abstract class M extends Base<B> {
}

class X extends Base<C> with M {
  bool problem() => f.c;
}

Here class X is extending Base<C> and also mixing class M which extends Base<B> where C extends B. Base<T> has a getter f returning T. In class X which extends Base<C> therefore it is expected that f returns C. However Fasta in strong mode reports:

flu.dart:19:19: Error: The getter 'c' isn't defined for the class '#lib1::B'.
Try correcting the name to the name of an existing getter, or defining a getter or field named 'c'.
   bool get c => f.c;
                   ^

This means it thinks f returns B and not C. Furthermore Fasta also generates throw of a compile error in X.problem body.

    method problem() → core::bool
      return (let final dynamic #t1 = this.{flu::Base::f} in let dynamic _ = null in const core2::_ConstantExpressionError::•().{core2::_ConstantExpressionError::_throw}(new core2::_CompileTimeError::•("file:///usr/local/google/home/vegorov/src/dart/sdk/t/flu.dart:19:23: Error: The getter 'c' isn't defined for the class '#lib1::B'.\nTry correcting the name to the name of an existing getter, or defining a getter or field named 'c'.\n  bool problem() => f.c;\n                      ^"))) as{TypeError} core2::bool;

@lrhn can you take a look at this code and say if it is expected to compile and run correctly according to the current thinking about mixins in Dart 2.

If it is we will need this to be fixed in Fasta.

I am marking this as P0 because this completely blocks us from running Flutter in strong mode with no workaround available.

/cc @lrhn @leafpetersen @stereotype441 @kmillikin @a-siva

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions