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

Returning int from an async function typed FutureOr<int> fails in dart2js #33639

Closed
kevmoo opened this issue Jun 26, 2018 · 4 comments
Closed
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js
Milestone

Comments

@kevmoo
Copy link
Member

kevmoo commented Jun 26, 2018

Dart -dev.64.1 and -dev.65

The following test succeeds with the VM and fails with dart2js with TypeErrorImplementation

import 'dart:async';
import 'package:test/test.dart';

void main() {
  test('sample', () async {
    var result = await _something();
    expect(result, 42);
  });
}

FutureOr<int> _something() async => 42;
  Async function returned a Future, was declared to return a FutureOr<int>.
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/js_helper.dart 1764:37   Object.wrapException
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/js_rti.dart 646:3        Object.throwTypeError
  test/sample_test.dart 16:37                                                   <fn>
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 335:19  _wrapJsFunctionForAsync.closure.$protected
  package:stack_trace                                                           StackZoneSpecification._registerBinaryCallback.<fn>
  org-dartlang-sdk:///sdk/lib/_internal/js_runtime/lib/async_patch.dart 251:3   Object._asyncStartSync
  test/sample_test.dart 16:37                                                   Object._something

Source issue: dart-archive/shelf_test_handler#5

@kevmoo kevmoo added P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js labels Jun 26, 2018
@kevmoo kevmoo added this to the Dart2Stable milestone Jun 26, 2018
@kevmoo
Copy link
Member Author

kevmoo commented Jun 26, 2018

CC @vsmenon RE dart2 regressions
CC @sigmundch RE dart2js
CC @leafpetersen RE FutureOr fun...

@sigmundch
Copy link
Member

@kevmoo I cannot repro this locally. I tried both 64.1 and 65. What am I doing wrong?

@sigmundch
Copy link
Member

Fix underway in https://dart-review.googlesource.com/c/sdk/+/62442

The problem was related to the --checked flag. Dart2js prints a warning if you are in Dart2 and pass --checked, in that case it should only enable assertions (for now). When dart2js switched the default to Dart2, we started processing the --checked flag incorrectly and all the sudden, we turned on Dart1 checked-mode checks in the generated code. Dart1 doesn't understand FutureOr, so the extra check automatically added a type-error at compile-time.

The CL above fixes how we handle the flag, but long term the flag will be a noop, so package:test should be updated to pass --enable-asserts instead.

@kevmoo
Copy link
Member Author

kevmoo commented Jun 26, 2018

package:test should be updated to pass --enable-asserts instead.

Underway - dart-lang/test#893 CC @natebosch

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js
Projects
None yet
Development

No branches or pull requests

2 participants