dart-lang / sdk

The Dart SDK, including the VM, JS and Wasm compilers, analysis, core libraries, and more.
https://dart.dev
BSD 3-Clause "New" or "Revised" License
10.27k stars 1.58k forks source link

VM crash when evaluating a named record field of a `late` variable #57048

Open DanTup opened 1 week ago

DanTup commented 1 week ago

Given this code, and a breakpoint on the marked line:

void main() {
  late var x = getThing();
  print('test'); // Breakpoint here
}

({int? a}) getThing() => (a: 1);

If you try to evaluate x.a (which at this point isn't initialized, though I hoped it would trigger initialization), the VM crashes with this error:

Connecting to VM Service at ws://127.0.0.1:50164/irJz-9Fkt2A=/ws
Connected to the VM Service.
x.a
../../runtime\vm/object.h: 8533: error: Handle check failed: saw sentinel expected Instance
version=3.7.0-edge.22833d51daf9f5c893010f284fc2cfb2f5d293f1 (main) (Thu Nov 7 03:40:54 2024 +0000) on "windows_x64"
pid=9012, thread=6348, isolate_group=main(000001CA55C69AC0), isolate=main(000001CA55CDE270)
os=windows, arch=x64, comp=no, sim=no
isolate_instructions=7ff6436c9c00, vm_instructions=7ff6436c9c20
fp=6ff46fc0d8, sp=6ff46fc0d8, pc=7ff643971972
  pc 0x00007ff643971972 fp 0x0000006ff46fc0d8 Dart_DetectNullSafety+0x29f812
-- End of DumpStackTrace
  pc 0x0000000000000000 fp 0x0000006ff46fc7d0 sp 0x0000000000000000 [Stub] CallToRuntime
  pc 0x000001ca55583d37 fp 0x0000006ff46fc820 sp 0x0000006ff46fc7e0 [Stub] OneArgCheckInlineCache
  pc 0x000001ca55f3a065 fp 0x0000006ff46fc850 sp 0x0000006ff46fc830 [Unoptimized] :Eval
  pc 0x000001ca555830ff fp 0x0000006ff46fc970 sp 0x0000006ff46fc860 [Stub] InvokeDartCode
  pc 0x0000000000000000 fp 0x0000006ff46fedc0 sp 0x0000000000000000 [Stub] CallToRuntime
  pc 0x000001ca55583bb1 fp 0x0000006ff46fedf0 sp 0x0000006ff46fedd0 [Stub] UnoptStaticCallBreakpoint
  pc 0x000001ca55f37655 fp 0x0000006ff46fee30 sp 0x0000006ff46fee00 [Unoptimized] main
  pc 0x000001ca55f39fcb fp 0x0000006ff46fee58 sp 0x0000006ff46fee40 [Unoptimized] main
  pc 0x000001ca55f39f02 fp 0x0000006ff46feeb8 sp 0x0000006ff46fee68 [Unoptimized] _Closure@0150898.dyn:call
  pc 0x000001ca55f38bae fp 0x0000006ff46feef8 sp 0x0000006ff46feec8 [Unoptimized] _delayEntrypointInvocation@1026248.<anonymous closure>
  pc 0x000001ca55f388d5 fp 0x0000006ff46fef60 sp 0x0000006ff46fef08 [Unoptimized] _Closure@0150898.dyn:call
  pc 0x000001ca55f37820 fp 0x0000006ff46fefb8 sp 0x0000006ff46fef70 [Unoptimized] _RawReceivePort@1026248._handleMessage@1026248
  pc 0x000001ca555830ff fp 0x0000006ff46ff0e0 sp 0x0000006ff46fefc8 [Stub] InvokeDartCode
evaluateInFrame: (-32000) Bad state: The client closed with pending request "evaluateInFrame".

Exited (-1073740791).
dart-github-bot commented 1 week ago

Summary: The VM crashes when evaluating a named record field of a late variable that hasn't been initialized yet. This occurs when trying to access the a field of x in the debugger, even though x is declared as late and hasn't been assigned a value.

a-siva commented 1 week ago

//cc @derekxu16

a-siva commented 1 week ago

Per discussion in the CFE sync meeting the general conclusion was

a-siva commented 5 days ago

Another option discussed in the triaged meeting was to implement initialization of late variables during expression evaluation and make the functionality similar to how we deal with non late variables. There would still be a number of issues with side effects that would be similar to the situation that we have today with non late variables.