Skip to content

DDC should move away from using JS default arguments for Dart methods with default parametersΒ #55884

@srujzs

Description

@srujzs
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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.dart2js-ddc-discrepancyWhen dev and production compilations have different semanticsweb-dev-compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions