Files
sdk/pkg/front_end/testcases/nnbd/potentially_non_nullable_field.dart
T
Dmitry Stefantsov 5af05598eb [cfe] Disallow non-nullable fields without initializers
Closes #40081.

Bug: http://dartbug.com/40081
Change-Id: I4032af18164af05034c2706cba8f62be39c636c4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/133994
Commit-Queue: Dmitry Stefantsov <dmitryas@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
2020-02-03 13:32:45 +00:00

33 lines
1020 B
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.
// The test checks for compile-time errors and their absence for cases involving
// fields of potentially non-nullable types.
int x; // Error.
int? y; // Ok: it's nullable.
late int z; // Ok: it's late.
class A<T extends Object?> {
static int x; // Error.
static int? y; // Ok: it's nullable.
static late int z; // Ok: it's late.
int lx; // Error.
int? ly; // Ok: it's nullable.
late int? lz; // Ok: it's late.
int lv; // Ok: initialized in an initializing formal.
int lu; // Ok: initialized in an initializer list entry.
T lt; // Error.
T? ls; // Ok: it's nullable.
late T lr; // Ok: it's late.
T lp; // Ok: initialized in an initializing formal.
T lq; // Ok: initialized in an initializer list entry.
A(this.lv, this.lp, T t) : this.lu = 42, this.lq = t;
}
main() {}