Files
sdk/pkg/front_end/testcases/static_field_lowering/opt_out.dart
T
Lasse R.H. Nielsen ef8cc2c1cf Remove LateInitializationError.
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>
2021-01-12 20:21:33 +00:00

104 lines
2.6 KiB
Dart

// Copyright (c) 2020, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// @dart=2.8
dynamic lastInit;
T init<T>(T value) {
lastInit = value;
return value;
}
const int constTopLevelField = 324;
int topLevelFieldWithoutInitializer;
int topLevelFieldWithInitializer1 = init(42);
int topLevelFieldWithInitializer2 = init(42);
final int finalTopLevelFieldWithInitializer1 = init(87);
int finalTopLevelFieldWithInitializer2Init = 0;
final int finalTopLevelFieldWithInitializer2 =
finalTopLevelFieldWithInitializer2Init++ == 0
? finalTopLevelFieldWithInitializer2 + 1
: 87;
class Class {
static const int staticConstField = 123;
int instanceFieldWithInitializer = init(55);
static int staticFieldWithoutInitializer;
static int staticFieldWithInitializer1 = init(55);
static int staticFieldWithInitializer2 = init(55);
static final int staticFinalFieldWithInitializer1 = init(73);
static int staticFinalFieldWithInitializer2Init = 0;
static final int staticFinalFieldWithInitializer2 =
staticFinalFieldWithInitializer2Init++ == 0
? staticFinalFieldWithInitializer2 + 1
: 87;
}
main() {
expect(null, lastInit);
expect(null, topLevelFieldWithoutInitializer);
expect(324, constTopLevelField);
expect(null, Class.staticFieldWithoutInitializer);
expect(123, Class.staticConstField);
expect(42, topLevelFieldWithInitializer1);
expect(42, lastInit);
topLevelFieldWithInitializer2 = 56;
expect(42, lastInit);
expect(56, topLevelFieldWithInitializer2);
expect(42, lastInit);
expect(87, finalTopLevelFieldWithInitializer1);
expect(87, lastInit);
throws(() => finalTopLevelFieldWithInitializer2,
'Read finalTopLevelFieldWithInitializer2');
expect(55, Class.staticFieldWithInitializer1);
expect(55, lastInit);
Class.staticFieldWithInitializer2 = 63;
expect(55, lastInit);
expect(63, Class.staticFieldWithInitializer2);
expect(55, lastInit);
expect(73, Class.staticFinalFieldWithInitializer1);
expect(73, lastInit);
throws(() => Class.staticFinalFieldWithInitializer2,
'Read staticFinalFieldWithInitializer2');
var c = new Class();
expect(55, lastInit);
expect(55, c.instanceFieldWithInitializer);
}
expect(expected, actual) {
if (expected != actual) throw 'Expected $expected, actual $actual';
}
throws(f(), String message) {
dynamic value;
try {
value = f();
} catch (e) {
print(e);
return;
}
throw '$message: $value';
}