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

[dart2js] Incorrect code generated in body of a function used as a .call getter #55298

Open
nshahan opened this issue Mar 25, 2024 · 0 comments
Labels
area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js

Comments

@nshahan
Copy link
Contributor

nshahan commented Mar 25, 2024

There is some randomness thrown into this example to avoid inlining.

import 'dart:math';

class C {
  int Function(String) get call => (s) => s.length;
}

main() {
  var s = '${Random().nextBool() ? 'hello' : 'goodbye'} world';
  print(s.length); // prints as expected
  var c = C();
  print(c.call(s)); // boom!
}

In the main method s.length gets compiled to s.length in JavaScript.

In the body of the .call function s.length gets compiled to s.get$length in JavaScript which is not defined and will cause an error to be thrown.

Uncaught TypeError: s.get$length is not a function
    at C_call_closure.call$1 (out.js:2628:16)
    at C.call$1 (out.js:2623:31)
    at main (out.js:2322:25)
    at out.js:2728:7
    at out.js:2709:7
    at dartProgram (out.js:2722:5)
    at out.js:2731:3
@nshahan nshahan added web-dart2js type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) area-web Use area-web for Dart web related issues, including the DDC and dart2js compilers and JS interop. labels Mar 25, 2024
@sigmundch sigmundch added the P3 A lower priority bug or feature request label Mar 25, 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. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js
Projects
None yet
Development

No branches or pull requests

2 participants