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

[ddc] error on type checks for records #52480

Closed
treeplate opened this issue May 22, 2023 · 1 comment
Closed

[ddc] error on type checks for records #52480

treeplate opened this issue May 22, 2023 · 1 comment
Assignees
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. P1 A high priority bug; for example, a single project is unusable or has many test failures web-dev-compiler

Comments

@treeplate
Copy link

void main() {
  TowerArea towerArea = TowerArea();
  towerArea.tick();
  print('success');
  //runApp(const MyApp());
}

class TowerArea {
  final List<(double, double)> coins = [(0, 0)];

  void tick() {
    (double, double) coin = coins.first;
    coins[0] = (coin.$1, coin.$2 + .01);
  }
}

In DartPad, this prints success.
In native, this prints success.
In Flutter for Web, this throws the following error:

Error: Expected a value of type '(double, double)', but got one of type '(int, double)'
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 294:49      throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 127:3       castError
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 738:12  cast
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/types.dart 2319:12      as
dart-sdk/lib/_internal/js_dev_runtime/private/js_array.dart 596:34                _set]
packages/<your package>/main.dart 15:10                                                tick
packages/<your package>/main.dart 5:12                                                 main$
web_entrypoint.dart 24:31                                                         <fn>
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 570:37  _checkAndCall
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 575:39  dcall
lib/ui/initialization.dart 77:15                                                  <fn>
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50                <fn>
dart-sdk/lib/async/zone.dart 1661:54                                              runUnary
dart-sdk/lib/async/future_impl.dart 153:18                                        handleValue
dart-sdk/lib/async/future_impl.dart 837:44                                        handleValueCallback
dart-sdk/lib/async/future_impl.dart 866:13                                        _propagateToListeners
dart-sdk/lib/async/future_impl.dart 638:5                                         [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 712:7                                         callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                                  _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                                   _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 181:15               <fn>

I'm using MacOS/Chrome however I have also tested on Windows10/Edge with similar results.
flutter --version

Flutter 3.11.0-11.0.pre.8 • channel master • https://github.com/flutter/flutter.git
Framework • revision 343718945b (6 hours ago) • 2023-05-22 14:11:18 -0400
Engine • revision e04c14786d
Tools • Dart 3.1.0 (build 3.1.0-129.0.dev) • DevTools 2.23.1

dart --version
Dart SDK version: 3.1.0-129.0.dev (dev) (Fri May 19 12:10:06 2023 -0700) on "macos_arm64"

@sigmundch sigmundch added web-dev-compiler area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. labels May 23, 2023
@sigmundch sigmundch changed the title flutter dart2js record typing throws error [ddc] error on type checks for records May 23, 2023
@sigmundch
Copy link
Member

Thanks for filing the issue - updated the title slightly.

There are discrepancies in our subtyping check for records in DDC (dev-mode) compared to dart2js (production), but it appears it is specific to web numbers.

Here is a similar program showing the issue:

main() {
  (double, double) a = (0, 0.1);
  Object b = a;
  b as (double, double);
}

This fails with a cast error Error: Expected a value of type '(double, double)', but got one of type '(int, double)'

And this programs shows different results depending on the backend:

main() {
  Object a = (0, 0.1);             
  (double, double) b = (0, 0.1);   //  implicit conversion based on typing context
  Object c = b;
                                   //   Prints on VM, dart2js,     ddc
  print(a is (double, double));    //          false,    true,   false
  print(a is (int, double));       //           true,    true,    true
  print(c is (double, double));    //           true,    true,   false
  print(c is (int, double));       //          false,    true,    true
}

The column on dart2js seems the expected semantics given how int are subtypes of double on the web.

In particular, the following program correctly prints true 4 times on all backends:

class A {}              // mimic `double` on the web
class B extends A {}    // mimic `int` on the web.
main() {
  Object a = (B(), A());
  (A, A) b = (B(), A());
  Object c = b;
  print(a is (A, A));
  print(a is (B, A));   // mimic (int, double)
  print(c is (A, A));
  print(c is (B, A));
}

@nshahan nshahan added the P1 A high priority bug; for example, a single project is unusable or has many test failures label May 24, 2023
copybara-service bot pushed a commit that referenced this issue May 25, 2023
See: #52480

Change-Id: Ife785a2f77579b93854779e43ac349342ac06af3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/305480
Reviewed-by: Nicholas Shahan <nshahan@google.com>
copybara-service bot pushed a commit that referenced this issue May 31, 2023
Bug: #52480
Change-Id: Iad9f6c986d4c445558c105abc66ad9b2a2812f25
Cherry-pick: https://dart-review.googlesource.com/c/sdk/+/305560
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/306307
Reviewed-by: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Mark Zhou <markzipan@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. P1 A high priority bug; for example, a single project is unusable or has many test failures web-dev-compiler
Projects
None yet
Development

No branches or pull requests

4 participants