ef8cc2c1cf
As per planned breaking change to let platforms decide how they and what throw for late initiaization errors, we no longer need a public `LateInitializationError` class. It's confusing to have one if some platforms throw something else instead. Removes the public abstract class. The dart:_internal implementation class `LateError` no longer implements it. This is the only implementation of the public interface, and the class which platforms either throw directly, or through front-end lowering of the feature. Remove mentions in tests. All tests now just expect `Error`, some platform specific tests might test the message. TEST=rewrote tests referring to LateInitializationError. Change-Id: I54344a67f89ce101ed770412db134e12354cdcc4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/174928 Commit-Queue: Lasse R.H. Nielsen <lrn@google.com> Reviewed-by: Nate Bosch <nbosch@google.com>
49 lines
1.9 KiB
Plaintext
49 lines
1.9 KiB
Plaintext
library /*isNonNullableByDefault*/;
|
|
import self as self;
|
|
import "dart:core" as core;
|
|
import "dart:_internal" as _in;
|
|
|
|
static method main(core::List<core::String> args) → dynamic {
|
|
lowered () →? core::int #recursiveInitLocal;
|
|
function #recursiveInitLocal#get() → () → core::int
|
|
return let final () →? core::int #t1 = #recursiveInitLocal in #t1.==(null) ?{() → core::int} throw new _in::LateError::localNI("recursiveInitLocal") : #t1{() → core::int};
|
|
function #recursiveInitLocal#set(() → core::int #t2) → dynamic
|
|
return #recursiveInitLocal = #t2;
|
|
lowered final core::int? #local;
|
|
function #local#get() → core::int
|
|
return let final core::int? #t3 = #local in #t3.==(null) ?{core::int} let final core::int #t4 = #recursiveInitLocal#get.call().call() in #local.==(null) ?{core::int} #local = #t4 : throw new _in::LateError::localADI("local") : #t3{core::int};
|
|
core::bool doRecursiveInitLocal = true;
|
|
#recursiveInitLocal#set.call(() → core::int {
|
|
core::print("Executing initializer");
|
|
if(doRecursiveInitLocal) {
|
|
doRecursiveInitLocal = false;
|
|
core::print("Trigger recursive initialization");
|
|
core::int val = #local#get.call();
|
|
core::print("Final local has value ${val}");
|
|
core::print("Returning 4 from initializer");
|
|
return 4;
|
|
}
|
|
core::print("Returning 3 from initializer");
|
|
return 3;
|
|
});
|
|
self::throws(() → Null {
|
|
core::int val = #local#get.call();
|
|
core::print("Final local has value ${val}");
|
|
}, "Read local");
|
|
}
|
|
static method expect(dynamic expected, dynamic actual) → dynamic {
|
|
if(!expected.{core::Object::==}(actual))
|
|
throw "Expected ${expected}, actual ${actual}";
|
|
}
|
|
static method throws(() → dynamic f, core::String message) → dynamic {
|
|
dynamic value;
|
|
try {
|
|
value = f.call();
|
|
}
|
|
on core::Error catch(final core::Error e) {
|
|
core::print(e);
|
|
return;
|
|
}
|
|
throw "${message}: ${value}";
|
|
}
|