-
Notifications
You must be signed in to change notification settings - Fork 40
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
Add ++i
and --i
support
#118
Add ++i
and --i
support
#118
Conversation
Resolves #4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good! Two comments; also, your tests should probably test the return values of the postfix/prefix expressions since that's the main difference between them.
Reference V, | ||
TypeRef type, | ||
Variable L, | ||
) { | ||
var out = L; | ||
|
||
if (L.name != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would happen if L.name
was null? like if you did:
final list = [1];
final result = ++list[0];
print(result);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm realizing that you just took that from the postfix.dart
code so this one's my fault actually, sorry! Still, if you wouldn't mind that check should be removed from both prefix and postfix, it's incorrect
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, for See below++list[0]
, this happens:
dart_eval runtime exception: type 'int' is not a subtype of type '$Value'
#0 BoxList.run (package:dart_eval/src/eval/runtime/ops/primitives.dart:255:69)
#1 Runtime.execute (package:dart_eval/src/eval/runtime/runtime.dart:787:12)
#2 Runtime.executeLib (package:dart_eval/src/eval/runtime/runtime.dart:775:12)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After removal of if (L.name != null)...
plus_plus and minus_minus works for both prefix and postfix, but there's an issue with boxing I think?
As you can see in the failed test, doing
List<int> list = [0];
print(list[0]++);
print(list[0]);
causes
dart_eval runtime exception: type 'int' is not a subtype of type '$Value?' in type cast
#0 InvokeExternal.run (package:dart_eval/src/eval/runtime/ops/bridge.dart:101:34)
#1 Runtime.execute (package:dart_eval/src/eval/runtime/runtime.dart:787:12)
#2 Runtime.executeLib (package:dart_eval/src/eval/runtime/runtime.dart:775:12)
where
List<int> list = [0];
print(list[0]);
print(list[0]++);
works fine.
Not sure how to fix that, also doing any other list reading with eg. print(list)/print(list.first)
after plus_plus/minus_minus prefix/postfix also causes similar issues:
print(list)
:
dart_eval runtime exception: type 'int' is not a subtype of type '$Value'
#0 BoxList.run (package:dart_eval/src/eval/runtime/ops/primitives.dart:255:69)
#1 Runtime.execute (package:dart_eval/src/eval/runtime/runtime.dart:787:12)
#2 Runtime.executeLib (package:dart_eval/src/eval/runtime/runtime.dart:775:12)
print(list.first)
:
dart_eval runtime exception: type 'int' is not a subtype of type '$Value'
#0 BoxList.run (package:dart_eval/src/eval/runtime/ops/primitives.dart:255:69)
#1 Runtime.execute (package:dart_eval/src/eval/runtime/runtime.dart:787:12)
#2 Runtime.executeLib (package:dart_eval/src/eval/runtime/runtime.dart:775:12)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Above also happens for current master
so we can rule out the possibility of introducing this issue with changes in this PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok that turned out to be a bit of a rabbit hole that I wouldn't expect you to dive into at this point, so I went ahead and pushed a fix to reference.dart in the v0.7.0 branch. If you pull it in, you should be able to do return V.setValue(ctx, result);
on line 82 of prefix.dart and everything will work correctly.
TLDR: lists in dart_eval are expected to contain only boxed types like $int
, but we were passing an unboxed int
to setValue and it was just setting that directly into the list. You should be able to pass anything to setValue and let it figure it out, so I made setValue box/unbox the argument you pass it automatically. The caller of setValue needs to be informed about this change though otherwise it will think the variable is still in its previous boxing state, so I also made it return the argument.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With your changes, list access is now working correctly, thanks!
40eccf7
to
22386d8
Compare
No description provided.