Skip to content

Dart2Js does wrong check of types #10535

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

Closed
DartBot opened this issue May 8, 2013 · 4 comments
Closed

Dart2Js does wrong check of types #10535

DartBot opened this issue May 8, 2013 · 4 comments
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue

Comments

@DartBot
Copy link

DartBot commented May 8, 2013

This issue was originally filed by @budde377


What steps will reproduce the problem?
1.
Compile


import "dart:math";

dynamic a;
Function f;

void test({String s1, String s2}) {
  s1 = ?s1 ? s1 : "string1";
  s1 = ?s2 ? s2 : "string2";
  if(new Random().nextBool()){
   f = (){
      print("$s1 $s2");
   };
  }
}

main() {
  test(s2:a);
}


with dart2js
2.
Run

What is the expected output? What do you see instead?
Expected:
No errors

Got:

Uncaught type 'anonymous' is not a subtype of type 'String'
main.dart.js:300
$.stringTypeCheck main.dart.js:300
$.test main.dart.js:178
$.main main.dart.js:187
(anonymous function) main.dart.js:624

What version of the product are you using? On what operating system?
dartium-lucid64-full-trunk-22223.0
on Ubuntu 12.10 64bit
I have dart-sdk revision 22231 installed

Please provide any additional information below.
The program compiles to:


...

$.test = function(s1, s2) {
  var t1, t2, t3;
  t1 = {};
  t1.s1_0 = s1;
  t2 = $ === s1;
  if (t2)
    t1.s1_0 = null;
  t3 = $ === s2;
  if (t3)
    s2 = null;
  $.stringTypeCheck(s1);
  $.stringTypeCheck(s2);
  t1.s1_0 = $.stringTypeCheck(!t2 ? t1.s1_0 : "string1");
  t1.s1_0 = !t3 ? s2 : "string2";
  if (Math.random() < 0.5)
    $.f = new $.test_anon(t1, s2);
};

$.main = function() {
  $.test($, $.a);
};

...


The checks

  $.stringTypeCheck(s1);
  $.stringTypeCheck(s2);

should be

  $.stringTypeCheck(t1.s1_0);
  $.stringTypeCheck(t1.s2_0);

@DartBot
Copy link
Author

DartBot commented May 8, 2013

This comment was originally written by @budde377


This will also fail on the code:

void test({String s1, String s2}) {
  s1 = ?s1 ? s1 : "string1";
  s1 = ?s2 ? s2 : "string2";
  f = (){
    print("$s1 $s2");
  };
}

@dgrove
Copy link
Contributor

dgrove commented May 9, 2013

The unary ? operator is being removed from the language shortly, so if this is related only to "?", this will not be fixed.

Can you try this test with some sort of sentinel default value to see if that works (since that will be the recommended pattern for this sort of thing going forward)?


Added NeedsInfo label.

@DartBot
Copy link
Author

DartBot commented May 9, 2013

This comment was originally written by @budde377


It that I can't reproduce the error without the ? operator.
Why will the operator be removed?

@dgrove
Copy link
Contributor

dgrove commented May 9, 2013

see issue #10466 for more detail


Added WontFix label.

@kevmoo kevmoo added closed-not-planned Closed as we don't intend to take action on the reported issue and removed resolution-wont_fix labels Mar 1, 2016
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-not-planned Closed as we don't intend to take action on the reported issue
Projects
None yet
Development

No branches or pull requests

3 participants