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

Future produced by async function has wrong type argument #49424

Closed
mraleph opened this issue Jul 8, 2022 · 1 comment
Closed

Future produced by async function has wrong type argument #49424

mraleph opened this issue Jul 8, 2022 · 1 comment
Assignees
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. cherry-pick-candidate Candidates to be cherry-picked type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@mraleph
Copy link
Member

mraleph commented Jul 8, 2022

Originally posted by @TimWhiting in #49345 (comment)

A future related test is failing on flutter/dart master with the fpdart library, found while creating this pull request to fix mixin breaking changes to work on master. I believe I'm running with a new enough sdk to incorporate the soundness fix.

SandroMaglione/fpdart#42

This is the test.

 test('run', () async {
      final task = Task.of(10);
      final future = task.run();
      expect(future, isA<Future<int>>());
      final r = await future;
      expect(r, 10);
 });

This is the relevant bit of Task

/// [Task] represents an asynchronous computation that yields a value of type `A` and **never fails**.
///
/// If you want to represent an asynchronous computation that may fail, see [TaskEither].
class Task<A>  {
  final Future<A> Function() _run;

  /// Build a [Task] from a function returning a [Future].
  const Task(this._run);

  /// Build a [Task] that returns `a`.
  factory Task.of(A a) => Task<A>(() async => a);

  /// Run the task and return a [Future].
  Future<A> run() => _run();
}

dart version:

dart --version
Dart SDK version: 2.18.0-263.0.dev (dev) (Thu Jul 7 10:24:22 2022 -0700) on "macos_x64"

output

00:05 +558 -1: test/src/task_test.dart: Task run [E]                                                                                                                                  
  Expected: <Instance of 'Future<int>'>
    Actual: <Instance of 'Future<dynamic>'>
     Which: is not an instance of 'Future<int>'
  
  package:test_api              expect
  test/src/task_test.dart 83:7  main.<fn>.<fn>

Standalone repo with just the above code, able to reproduce:
https://github.com/TimWhiting/dart_fail_future

Analyzer shows the correct type when hovering over the future returned from Task.run()

@mraleph mraleph added the area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. label Jul 8, 2022
@mraleph mraleph assigned mraleph and alexmarkov and unassigned mraleph Jul 8, 2022
@mraleph
Copy link
Member Author

mraleph commented Jul 8, 2022

Likely related to the new async implementation.

@lrhn lrhn added the type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) label Jul 8, 2022
@a-siva a-siva added the cherry-pick-candidate Candidates to be cherry-picked label Jul 19, 2022
copybara-service bot pushed a commit that referenced this issue Jul 26, 2022
In order to create a Future for the result of async closure,
closure needs to instantiate a type argument of its result type.
The result type may reference type arguments of enclosing function or
class and scope builder should visit closure's result type
in order to capture receiver or type arguments variable of parent
factory.

TEST=runtime/tests/vm/dart/regress_49424_test.dart
Fixes #49424

Change-Id: I1cd131251717fca43f8ca95856d13718eb9aca68
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/251320
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, FFI, and the AOT and JIT backends. cherry-pick-candidate Candidates to be cherry-picked type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

4 participants