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 result runs different logic from original dart code #16996

Closed
rinick opened this issue Feb 20, 2014 · 5 comments
Closed

dart2js result runs different logic from original dart code #16996

rinick opened this issue Feb 20, 2014 · 5 comments
Assignees
Labels
P0 A serious issue requiring immediate resolution web-dart2js

Comments

@rinick
Copy link

rinick commented Feb 20, 2014

compile this to js

  void main() {
    testValue([]);
    testValue(null);
  }
  List rslt = [];
  void testValue(List list) {
    if (list == null){
      rslt.add(1);
    }
    if (list == null || list.contains("2")){
      rslt.add(2);
    }
    if (list == null || list.contains("3")){
      rslt.add(3);
    }
  }

dart2js result:

  main: function() {
    G.testValue([]);
    G.testValue(null);
  },
  testValue: function(list) {
    var t1 = list == null;
    if (t1)
      $.get$rslt().push(1);
    t1 = !t1;
    if (t1 || J.contains$1$as(list, "2"))
      $.get$rslt().push(2);
    if (t1 || J.contains$1$as(list, "3"))
      $.get$rslt().push(3);
  }

in the js code it adds a weird line: t1 = !t1, which cause run time error of calling a method of null

after removing that line in js code everything works correctly.

@kevmoo
Copy link
Member

kevmoo commented Feb 20, 2014

Added Area-Dart2JS, Triaged labels.

@floitschG
Copy link
Contributor

Set owner to @floitschG.
Removed Priority-Unassigned label.
Added Priority-High label.

@floitschG
Copy link
Contributor

While trying to minimize I stumbled upon another (probably related) issue.
The following code executes foo twice.

foo(x) {
  if (x != 0) return foo(x - 1);
  if (x == -1) return 499;
  print("foo");
  return null;
}

main() {
  var x = foo(9999);
  if (x == null || foo(4) == null) return 1;
  if (x == null || foo(5) == null) return 2;
}


Removed Priority-High label.
Added Priority-Critical label.

@floitschG
Copy link
Contributor

@floitschG
Copy link
Contributor

Fixed in r32951.


Added Fixed label.

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P0 A serious issue requiring immediate resolution web-dart2js
Projects
None yet
Development

No branches or pull requests

3 participants