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 generates incorrect code for 'x is int' #3814

Closed
DartBot opened this issue Jun 21, 2012 · 11 comments
Closed

dart2js generates incorrect code for 'x is int' #3814

DartBot opened this issue Jun 21, 2012 · 11 comments
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js
Milestone

Comments

@DartBot
Copy link

DartBot commented Jun 21, 2012

This issue was originally filed by rice@google.com


The test program:

void main() {
  var a = 17179869184; // 2^34
  // Defeat compile-time evaluation
  if (2 + 2 != 4) {
    a = 2.0;
  }
  if (a is int) {
    print("int");
  } else {
    print("not int");
  }
}

generates code like:

$.main = function() {
  var a = 17179869184;
  if (typeof a === 'number' && a === (a | 0)) $.print('int');
  else $.print('not int');
};

which prints 'not int' due to the unnecessary coercion applied by '(a | 0)'. This problem exists even when the checked mode compiler flag is not used.

@rakudrama
Copy link
Member

The results of int-only operations are sometimes int and sometimes not:

id(x) => x;

main() {
  var x = id(1);
  var y = (x << 31);
  print('y = $y');
  print('y is int = ${id(y) is int}');
  y = (x << 30);
  print('y = $y');
  print('y is int = ${id(y) is int}');
}

y = 2147483648
y is int = false
y = 1073741824
y is int = true

@DartBot
Copy link
Author

DartBot commented Jun 21, 2012

This comment was originally written by rice@google.com


It was pointed out to me today that there's no possible test for 'int-ness' that can get the code below right. In JS, there's no way to tell the difference between a dart 'int' object and a dart 'double' that happens to have an integral value:

var x = 1.0;
if (x is int) {
  print('int');
} else if (x is double) {
  print('double');
} else {
  print('other');
}

@peter-ahe-google
Copy link
Contributor

We are not sure that our int tests are working well.

Unfortunately, changing the int test is complicated, so it may take some time to get this changed.

Also, the changes we can make initially will not allow dart2js to implement the same semantics as the VM.

I think the best thing we can do for now is help you by advising on how to solve your tasks.

I think for the intXX libraries you're working on, the best approach for now is to only use num when testing types. Please let us know if that causes problems.

@DartBot
Copy link
Author

DartBot commented Jun 22, 2012

This comment was originally written by rice@google.com


Thanks, I'll see whether I can get by with testing against 'num' in the fixnum and protobuf libraries.

@floitschG
Copy link
Contributor

Related (possibly duplicate): issue #3720

@kasperl
Copy link

kasperl commented Sep 3, 2012

Set owner to @floitschG.
Added this to the M1 milestone.

@kasperl
Copy link

kasperl commented Sep 7, 2012

Upping the priority of this one. We're having a hard time dealing with the checked mode issues that fall out of the limited range we support for ints.


Removed Priority-Medium label.
Added Priority-High label.

@kasperl
Copy link

kasperl commented Sep 7, 2012

Issue #2983 has been merged into this issue.


cc @floitschG.

@kasperl
Copy link

kasperl commented Sep 7, 2012

Set owner to ngeoffray@google.com.

@DartBot
Copy link
Author

DartBot commented Sep 7, 2012

This comment was originally written by ngeoffray@google.com


Issue #4980 has been merged into this issue.


cc @peter-ahe-google.
cc @ricowind.

@DartBot
Copy link
Author

DartBot commented Sep 7, 2012

This comment was originally written by ngeoffray@google.com


We're now checking for all integers that JS can represent in its primitive number type. See https://chromiumcodereview.appspot.com/10912147/.


Added Fixed label.

@DartBot DartBot added Type-Defect P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js labels Sep 7, 2012
@DartBot DartBot added this to the M1 milestone Sep 7, 2012
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 A high priority bug; for example, a single project is unusable or has many test failures web-dart2js
Projects
None yet
Development

No branches or pull requests

5 participants