Closed lrhn closed 1 month ago
The VM emits a diagnostic
../../play1/56803.dart:8:16: Error: Constant evaluation error:
var c= const Ext();
^
../../play1/56803.dart:4:22: Context: This assertion failed with message: Must not be null
: assert(maybes != null, "Must not be null"),
^
For dart2js, it seems like the evaluation of the constant is being deferred, possibly because dart2js (IIRC) resolves const bool.fromEnvironment
later if it is not defined.
AbortConstant? checkAssert(AssertStatement statement) {
if (!enableAsserts) return null;
final Constant condition = _evaluateSubexpression(statement.condition);
if (condition is AbortConstant) return condition;
if (shouldBeUnevaluated) {
// Coverage-ignore-block(suite): Not run.
Expression? message = null;
if (statement.message != null) {
enterLazy();
Constant constant = _evaluateSubexpression(statement.message!);
if (constant is AbortConstant) return constant;
message = _wrap(constant);
leaveLazy();
}
// v this is the crash
instanceBuilder!.asserts.add(new AssertStatement(_wrap(condition),
message: message,
conditionStartOffset: statement.conditionStartOffset,
conditionEndOffset: statement.conditionEndOffset));
} else if (condition is BoolConstant) {
// VM takes this path?
/cc @johnniwinther, @fishythefish
I'm not sure why we don't have an instanceBuilder
.
There seems to be an assumption that a constant-folded assert must be in the initializers of a regular constructor.
Has the extension type constructor been lowered to a static method?
The extension type constructor has been lowered and checkAssert
hasn't been updated accordingly. I'll look into it.
Given the following code:
Dart2JS (on Windows 10) crashes with the error message included below.
It does not seem to happen if converting
Ext
to a class. It does not seem to happen ifmaybes
is a literalnull
.Error: