Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyzer and compiler disagree on whether extension type implementing Future is FutureOr #55578

Closed
dgreensp opened this issue Apr 26, 2024 · 4 comments
Assignees
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues.

Comments

@dgreensp
Copy link

An extension type on Future that implements Future can be assigned to FutureOr, as far as the analyzer is concerned, but not as far as the compiler is concerned:

import "dart:async";

void main() async {
  // analyzer is ok with assigning a `Foo` to `FutureOr<int>`;
  // compilers (compileDDC, dart2js) give an error here
  final FutureOr<int> x = Foo(Future(() => 123));
  // use it
  print(x is Future<int> ? (await x) : x);
}

extension type Foo(Future<int> rep) implements Future<int> {}

Personally, I would prefer it be allowed, if it isn't too much trouble.

@sigmundch sigmundch added the area-front-end Use area-front-end for front end / CFE / kernel format related issues. label Apr 26, 2024
@johnniwinther
Copy link
Member

cc @eernstg @chloestefantsova

@eernstg
Copy link
Member

eernstg commented Apr 29, 2024

The type Foo is a subtype of Future<int> which is a subtype of FutureOr<int>, and there should not be an error at the initialization of x.

@eernstg
Copy link
Member

eernstg commented Apr 29, 2024

@sgrekhov, I think it would be useful to take a look at this and see why we don't have a test that catches this case. I noticed that the other union type does not get the same treatment:

// ignore_for_file: unused_local_variable

void main() async {
  final int? iq = Bar(42);
  int j = iq is int ? iq : 24; // OK.
}

extension type Bar(int _) implements int {}

@eernstg
Copy link
Member

eernstg commented Apr 29, 2024

Whoosh! That was fast, @chloestefantsova! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-front-end Use area-front-end for front end / CFE / kernel format related issues.
Projects
None yet
Development

No branches or pull requests

5 participants