Skip to content

Frog needs to ensure that list indices are integers within range #1155

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
dgrove opened this issue Jan 12, 2012 · 3 comments
Closed

Frog needs to ensure that list indices are integers within range #1155

dgrove opened this issue Jan 12, 2012 · 3 comments
Milestone

Comments

@dgrove
Copy link
Contributor

dgrove commented Jan 12, 2012

The tests below should all fail:

main() {
  var x = new List(5);
  x[1.1] = 1;
}

main() {
  var x = new List(5);
  x[6] = 1;
}

main() {
  var x = new List(5);
  x[-1] = 1;
}

main() {
  var x = new List(5);
  x['bar'] = 1;
}

@DartBot
Copy link

DartBot commented Jan 17, 2012

This comment was originally written by [email protected]


Before implementing, I verified what we were seeing on dartc.

For x[1.1] = 1; --> dartc reports no errors here and even happily accepts print(x[1.1]) and prints out "1.1". I believe that this is likely to be an expensive check to add in, so I understand why dartc doesn't do it. This is also compatible with my understand of the JS numeric model. I would like to pull this particular case out into a separate bug for independent tracking. Kasper - is this okay with you?

The truly out-of-range cases are handled correctly by dartc, however, it does fail with a fairly odd error on the x['bar'] case, printing "Object hi has no method 'LT$operator'". Intrigued by this behavior, I crafted this slightly different version for dartc which it will happily compile and run. I suspect that there is a way to use this approach to get dartc to demonstrate the same behavior as reported in issue #1054 - but I have not investigated enough to verify.

class C {
  operator <(o) => false;
  operator <=(o) => true;

  toString() => "hi";
}

main() {
  var x = new List(5);
  var o = new C();
  x[o] = 42;
  print("success");
}
  


cc @kasperl.
Set owner to [email protected].
Added Started label.

@kasperl
Copy link

kasperl commented Jan 17, 2012

Nice one, Jim! I think separating the out of bounds and the integer key check is very reasonable, but I also think we need to fix both issues. I'll try to fix the odd behavior in dartc -- should be extremely simple.

@DartBot
Copy link

DartBot commented Jan 24, 2012

This comment was originally written by [email protected]


Fixed in r3556.


Added Fixed label.

@dgrove dgrove added this to the FrogEditor milestone Jan 24, 2012
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants