Skip to content

CFE sometimes infers the wrong type for Future return types in interfaces across nullability boundaries. #40479

@Markzipan

Description

@Markzipan

Snippet below consists of two files:

Opted-out:

// @dart = 2.6

import 'tt.dart';
import "dart:async";

class B implements A<int> {
  then<B>() => Future<B>.value();
}

main() {}

Opted-in:

class A<R> {
  Future<T> then<T>() => Future<T>.value();
}

errors with the null-safety experiment enabled with:

Error: The return type of the method 'B.then' is 'dynamic', which does not match the return type, 'Future<B>', of the overridden method, 'A.then'.
 - 'Future' is from 'dart:async'.
Change to a subtype of 'Future<B>'.
  then<B>() => Future<B>.value();
  ^
Context: This is the overridden method ('then').
  Future<T> then<T>() => Future<T>.value();
            ^

but passes with the experiment disabled.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions