You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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");
}
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.
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;
}
The text was updated successfully, but these errors were encountered: