Skip to content

Implement error about awaiting a type that is incompatible with await #54647

Description

@eernstg

The PR dart-lang/language#3560 introduces the notion that a type can be incompatible with await. This concept is used to specify a new and broader error about expressions of the form await e where the static type of e has associations with an extension type that does not implement Future.

The previous rules just made it an error when the type was such an extension type, now it is also an error when it is T? where T is incompatible with await, or a type variable that extends such a type, etc. Details in dart-lang/language#3560. Example:

extension type N(Future<int> _) {}
extension type F(Future<int> _) implements Future<int> {}

void test<X, XN extends N, XF extends F>(
    N n, F f, X x, XN xn, XF xf, N? nq, F? fq, XN? xnq, XF? xfq) async {
  await n; // Error.
  await f; // OK, type `int`.
  await x; // OK, type `X`.
  await xn; // Error.
  await xf; // OK, type `int`.
  await nq; // Error.
  await fq; // OK, type `int?`.
  await xnq; // Error.
  await xfq; // OK, type `int?`.
  if (x is N) await x; // Error.
  if (x is N?) await x; // Error.
  if (x is XN) await x; // Error.
  if (x is XN?) await x; // Error.
  if (x is F) await x; // OK, type `int`.
  if (x is F?) await x; // OK, type `int?`.
  if (x is XF) await x; // OK, type `int`.
  if (x is XF?) await x; // OK, type `int?`.
}

Subtasks:

Metadata

Metadata

Assignees

Labels

area-metaCross-cutting, high-level issues (for tracking many other implementation issues, ...).feature-extension-typesImplementation of the extension type featureimplementationTrack the implementation of a specific feature (use on area-meta issue, not issues for each tool)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions