running a script with an if statement checking an int equality
maks opened this issue · comments
Maksim Lin commented
trying to eval this code:
void main() {
print(calc(50));
}
int calc(int sumTo) {
if (sumTo == 13) {
print("unlucky number!");
}
int accum = 0;
for (int i = 0; i < sumTo; i++) {
accum = accum + i;
}
return accum;
}
using:
import 'dart:io';
import 'package:dart_eval/dart_eval.dart';
void main(List<String> args) async {
final src = File(args[0]);
final program = src.readAsStringSync();
print(eval(program, function: 'main'));
}
Unfortunately produces the error below.
It seems to be to do with using the equality operator, as changing that to for instance a less-than operator allows the script to be eval'd without any errors.
Unhandled exception:
dart_eval runtime exception: type 'int' is not a subtype of type '$Value' in type cast
#0 Unbox.run (package:dart_eval/src/eval/runtime/ops/primitives.dart:307:48)
#1 Runtime.execute (package:dart_eval/src/eval/runtime/runtime.dart:620:12)
#2 Runtime.executeLib (package:dart_eval/src/eval/runtime/runtime.dart:608:12)
RUNTIME STATE
=============
Program offset: 99
Stack sample: [L0: 50, L1: 0, L2: 1, L3: true, L4: 0, L5: 1, L6: 1, L7: null, L8: null, L9: null]
Call stack: [0, -1, 76]
TRACE:
93: InvokeExternal (Ex#12)
94: PushReturnValue ()
95: Pop (2)
96: Pop (2)
97: PushConstantInt (0)
98: PushConstantInt (0)
99: Unbox (L0) <<< EXCEPTION
100: NumLt (L2 < L0)
101: JumpIfFalse (@112 if L3 == false)
102: NumAdd (L1 + L2)
#0 Runtime.execute (package:dart_eval/src/eval/runtime/runtime.dart:629:7)
#1 Runtime.executeLib (package:dart_eval/src/eval/runtime/runtime.dart:608:12)
#2 eval (package:dart_eval/src/eval/eval.dart:51:26)
#3 main (file:///home/maks/work/fast_dart/fsd_server/bin/darteval.dart:24:9)
#4 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:294:33)
#5 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:189:12)
Maksim Lin commented
Sorry I forgot to mention this is running on: Dart SDK version: 3.1.2 (stable) (Tue Sep 12 16:26:23 2023 +0000) on "linux_x64"
Ethan commented
Fixed in v0.6.1