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.25k stars 1.58k forks source link

VM crash when type `Never` is used #39466

Closed eernstg closed 4 years ago

eernstg commented 4 years ago

Consider the following two programs:

import 'dart:core' as core;

main() {
  core.Never n = throw "away";
}
main() {
  Never n = throw "away";
}

Both of them cause a crash in dart from commit 11d523dfe11dbf61a46f04b32d31c6181fcf073f (but dartanalyzer accepts the programs):

> dart --enable-experiment=non-nullable n039.dart; dart --enable-experiment=non-nullable n040.dart
Unhandled exception:
'file:///usr/local/google/home/eernst/lang/dart/scratch/201911/n039.dart': error: Unexpected tag 1 (Something) in ::.main, expected expression
#0      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:307:19)
#1      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)
Unhandled exception:
'file:///usr/local/google/home/eernst/lang/dart/scratch/201911/n040.dart': error: Unexpected tag 1 (Something) in ::.main, expected expression
#0      _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:307:19)
#1      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:174:12)

The NNBD specification indicates that Never is declared in 'dart:core', so both should work.

The following form causes the same crash (before execution starts), so it isn't caused by the use of throw "away" as an initializing expression:

import 'dart:core' as core;

main() {
  core.dynamic d = 42;
  core.Never n = d;
}
crelier commented 4 years ago

I am not sure why it works in dartanalyzer, but these errors are produced by the front-end. I am reassigning the issue.

sgrekhov commented 4 years ago

See also #39461

crelier commented 4 years ago

Never mind :-) Having a second look.

crelier commented 4 years ago

Although the type Never is always non-nullable, the CFE writes a nullability byte in kernel files that was not properly skipped by the VM. A CL is under review.

crelier commented 4 years ago

Fixed by https://github.com/dart-lang/sdk/commit/af541cd0dda958a35b17bfb2f5b58d5f4b7fd307