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

Fix #2490. Update incompatible with await tests according to the changed rule #2516

Merged
merged 2 commits into from
Feb 2, 2024

Conversation

sgrekhov
Copy link
Contributor

@sgrekhov sgrekhov commented Feb 1, 2024

No description provided.

Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again some tricky corners to consider. ;-)

Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more comment.

test<X extends NumET>(X x) async {
if (x is int) {
await x;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could probably do something like this:

extension type E1(Object _) {} // Incompatible with await.
extension type E2(Future<int> _) implements E1, Future<int> {} // Compatible.

Future<void> foo<X extends E1>(X x) async {
  E1 y = x;
  // await y; // Error, reported today.
  await x; // Error, `E` is not compatible with await. Not reported.
  if (x is E2) { // `x` has type `X & E2`.
    await x; // OK, result has type `int`.
  }
}

void main() async {
  await foo(E1(Future.value(1)));
}

(By the way, I just tried a completely fresh CFE, it does report an error for the line marked 'Not reported'. Moving fast. ;-)

@sgrekhov
Copy link
Contributor Author

sgrekhov commented Feb 2, 2024

I removed static_analysis_extension_types_A08_t12.dar. Indeed we can't do this. So, only update of asserts left.

extension type E1(Object _) {} // Incompatible with await.
extension type E2(Future<int> _) implements E1, Future<int> {} // Compatible.

Future<void> foo<X extends E1>(X x) async {
  E1 y = x;
  // await y; // Error, reported today.  <- this checked in `static_analysis_extension_types_A08_t01.dart`
  await x; // Error, `E` is not compatible with await. Not reported. <- checked in `static_analysis_extension_types_A08_t07.dart`
  if (x is E2) { // `x` has type `X & E2`.
    await x; // OK, result has type `int`. <- checked in `static_analysis_extension_types_A08_t11.dart`
  }
}

void main() async {
  await foo(E1(Future.value(1)));
}

So, I think, there is no need to add the test above. Please take another look

@eernstg
Copy link
Member

eernstg commented Feb 2, 2024

OK, updated asserts is a safe bet: Landing this.

However, I'm still wondering: Do we have a test that covers the case where we can a await e where e has type X & B where B is an extension type which is compatible with await, but X isn't (because the bound of X is an extension type that is not compatible)?

// Like this.
extension type E1(Object _) {} // Incompatible with await.
extension type E2(Future<int> _) implements E1, Future<int> {} // Compatible.

This is a tricky case because an algorithm that searches for an extension type that doesn't implement Future could search and find E1 and then conclude that X & E2 is incompatible with await, even though we're supposed to use the check on E2 directly (and ignore that we have a "bad" type in the superinterface graph).

Copy link
Member

@eernstg eernstg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eernstg eernstg merged commit 5125c01 into dart-lang:master Feb 2, 2024
2 checks passed
@sgrekhov
Copy link
Contributor Author

sgrekhov commented Feb 2, 2024

OK, updated asserts is a safe bet: Landing this.

However, I'm still wondering: Do we have a test that covers the case where we can a await e where e has type X & B where B is an extension type which is compatible with await, but X isn't (because the bound of X is an extension type that is not compatible)?

// Like this.
extension type E1(Object _) {} // Incompatible with await.
extension type E2(Future<int> _) implements E1, Future<int> {} // Compatible.

This is a tricky case because an algorithm that searches for an extension type that doesn't implement Future could search and find E1 and then conclude that X & E2 is incompatible with await, even though we're supposed to use the check on E2 directly (and ignore that we have a "bad" type in the superinterface graph).

Please see

// SharedOptions=--enable-experiment=inline-class
import 'dart:async';
extension type ObjectET(Object _) implements Object {}
extension type FutureIntET(Future<int> _) implements Future<int>, ObjectET {}
test<X extends ObjectET>(X x) async {
if (x is FutureIntET) {
await x;
}
if (x is FutureIntET?) {
await x;
}
}
main() {
test(FutureIntET(Future<int>.value(42)));
}

@eernstg
Copy link
Member

eernstg commented Feb 2, 2024

Great, thanks!

copybara-service bot pushed a commit to dart-lang/sdk that referenced this pull request Feb 5, 2024
2024-02-02 sgrekhov22@gmail.com Fix dart-lang/co19#2517. Fix wrong test, add experimental flags (dart-lang/co19#2518)
2024-02-02 sgrekhov22@gmail.com Fix dart-lang/co19#2490. Update incompatible with await tests according to the changed rule (dart-lang/co19#2516)
2024-02-01 sgrekhov22@gmail.com dart-lang/co19#2420. Add more exhaustiveness tests (dart-lang/co19#2513)
2024-01-31 sgrekhov22@gmail.com dart-lang/co19#2446. Add additional test for cast pattern (dart-lang/co19#2514)
2024-01-30 sgrekhov22@gmail.com dart-lang/co19#1399. Add more tests for records (dart-lang/co19#2511)
2024-01-30 sgrekhov22@gmail.com dart-lang/co19#2485. Update map and list constant literals tests. Add parenthesized for records (dart-lang/co19#2512)
2024-01-29 sgrekhov22@gmail.com Fixes dart-lang/co19#2490. Add more await tests for extension types (dart-lang/co19#2500)
2024-01-29 sgrekhov22@gmail.com dart-lang/co19#2119. Fix typo in Subtyping tests description (dart-lang/co19#2510)
2024-01-29 sgrekhov22@gmail.com Fixes dart-lang/co19#2505. Add more tests for `call` member (dart-lang/co19#2506)
2024-01-29 sgrekhov22@gmail.com dart-lang/co19#2420. Add cast-pattern tests for extension types (dart-lang/co19#2458)

Change-Id: I631705a013f9a77910ae0f0be5a9fea01e7c719f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350240
Reviewed-by: Erik Ernst <eernst@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
Reviewed-by: William Hesse <whesse@google.com>
sgrekhov added a commit to sgrekhov/co19 that referenced this pull request Feb 15, 2024
… the changed rule (dart-lang#2516)

Update incompatible with await tests according to the changed rule
sgrekhov added a commit to sgrekhov/co19 that referenced this pull request Feb 15, 2024
… the changed rule (dart-lang#2516)

Update incompatible with await tests according to the changed rule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants