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 should move away from using JS default arguments for Dart methods with default parameters #55884

Open
srujzs opened this issue May 30, 2024 · 0 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. dart2js-ddc-discrepancy When dev and production compilations have different semantics web-dev-compiler

Comments

@srujzs
Copy link
Contributor

srujzs commented May 30, 2024

import 'dart:js_interop';

@JS()
external String? get undefined;

void f([String? s = 'default']) {
  print(s);
}

void main() {
  f(undefined);
}

The above prints default on DDC and null on dart2js (also null on dart2wasm, but that's because of how it's converted to null explicitly). This is because DDC lowers f to something like:

function f(s = 'default') {
  dart.print(s);
}

When undefined is passed, JS uses the default value instead. This is generally an okay way to lower this code if undefined never exists in the program, but with JS interop, that can't be guaranteed. Another way to reproduce this discrepancy is converting the above Dart function to JS and then calling it with undefined.

cc @nshahan

@srujzs srujzs added web-dev-compiler area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. dart2js-ddc-discrepancy When dev and production compilations have different semantics labels May 30, 2024
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. dart2js-ddc-discrepancy When dev and production compilations have different semantics web-dev-compiler
Projects
None yet
Development

No branches or pull requests

1 participant