dart-sdk/tests/language/inference_update_2/why_not_promoted_error_test.dart
Lasse R.H. Nielsen 9d933d1281 Retire 3.3 experiments in the 3.4 release.
Tested: No new tests.
Change-Id: Idf19ce8b6743b221841e6cef6b2a80e8ab37860e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/354260
Auto-Submit: Lasse Nielsen <lrn@google.com>
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Nate Bosch <nbosch@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Lasse Nielsen <lrn@google.com>
2024-03-04 16:09:31 +00:00

54 lines
2 KiB
Dart

// Copyright (c) 2023, 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.
// Tests that the appropriate "why not promoted" context messages are shown when
// field promotion fails.
class C {
int? get _privateGetter => publicField;
// ^^^^^^^^^^^^^^
// [context 1] '_privateGetter' refers to a getter so it couldn't be promoted. See http://dart.dev/go/non-promo-non-field
// [context 4] '_privateGetter' refers to a getter so it couldn't be promoted.
final int? publicField;
// ^^^^^^^^^^^
// [context 2] 'publicField' refers to a public property so it couldn't be promoted. See http://dart.dev/go/non-promo-public-field
// [context 5] 'publicField' refers to a public property so it couldn't be promoted.
int? _nonFinalField;
// ^^^^^^^^^^^^^^
// [context 3] '_nonFinalField' refers to a non-final field so it couldn't be promoted. See http://dart.dev/go/non-promo-non-final-field
// [context 6] '_nonFinalField' refers to a non-final field so it couldn't be promoted.
C(int? i)
: publicField = i,
_nonFinalField = i;
}
void notAField(C c) {
if (c._privateGetter != null) {
c._privateGetter.isEven;
// ^^^^^^
// [analyzer 1] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// [cfe 4] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
}
}
void notPrivate(C c) {
if (c.publicField != null) {
c.publicField.isEven;
// ^^^^^^
// [analyzer 2] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// [cfe 5] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
}
}
void notFinal(C c) {
if (c._nonFinalField != null) {
c._nonFinalField.isEven;
// ^^^^^^
// [analyzer 3] COMPILE_TIME_ERROR.UNCHECKED_USE_OF_NULLABLE_VALUE
// [cfe 6] Property 'isEven' cannot be accessed on 'int?' because it is potentially null.
}
}
main() {}