Skip to content

No error in CFE in case of generic function override #60011

@sgrekhov

Description

@sgrekhov

I searched but didn’t find whether a similar issue already exists. Please close this one as a duplicate if it does.

The code below produces an error in the analyzer but works in CFE.

class A<T extends num> {
  X foo<X extends T>(X x) => x;
}

class C<T extends num> extends A<num> {
  int v;
  C(this.v);
  X foo<X extends T>(X x) => x + v as X; // Analyzer error.  'C.foo' ('X Function<X extends T>(X)') isn't a valid override of 'A.foo' ('X Function<X extends num>(X)').
}

void main() {
  var c = C<int>(1);
  print(c.foo(1)); // prints 2
}

@eernstg which tool is right here?

Dart SDK version: 3.8.0-38.0.dev (dev) (Sat Jan 25 16:01:44 2025 -0800) on "windows_x64"

Metadata

Metadata

Assignees

No one assigned

    Labels

    front-end-analyzer-unificationIssues where the analyzer and cfe vary (not clearly a bug on one or the other).legacy-area-front-endLegacy: Use area-dart-model instead.type-bugIncorrect behavior (everything from a crash to more subtle misbehavior)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions