-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[tests] Additional tests for ?? with enum shorthands.
Tests for `??` where context is from LHS and warnings when LHS is not nullable. Context: https://dart-review.googlesource.com/c/sdk/+/399520/comments/ee1b4e32_2a0ed6e7 Bug: #57038 Change-Id: I563d54b447e90f97fbea1a972f2e06c2cc23c8fe Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/401140 Commit-Queue: Kallen Tu <kallentu@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
- Loading branch information
Showing
7 changed files
with
205 additions
and
0 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
tests/language/enum_shorthands/constructor/constructor_if_null_error_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
// Errors with `??` and enum shorthands with constructors. | ||
|
||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
import '../enum_shorthand_helper.dart'; | ||
|
||
void constructorClassTest() { | ||
ConstructorClass ctor = ConstructorClass(1); | ||
|
||
// Warning when LHS is not able to be `null`. | ||
ConstructorClass notNullable = .new(1) ?? ctor; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
ConstructorClass notNullableRegular = .regular(1) ?? ctor; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
ConstructorClass notNullableNamed = .named(x: 1) ?? ctor; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
ConstructorClass notNullableOptional = .optional(1) ?? ctor; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
void constructorExtTest() { | ||
ConstructorExt ctorExt = ConstructorExt(1); | ||
|
||
// Warning when LHS is not able to be `null`. | ||
ConstructorExt notNullableExt = .new(1) ?? ctorExt; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
ConstructorExt notNullableRegularExt = .regular(1) ?? ctorExt; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
ConstructorExt notNullableNamedExt = .named(x: 1) ?? ctorExt; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
ConstructorExt notNullableOptionalExt = .optional(1) ?? ctorExt; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
tests/language/enum_shorthands/member/static_method_if_null_error_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
// Errors with `??` and enum shorthands with static members. | ||
|
||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
import '../enum_shorthand_helper.dart'; | ||
|
||
void memberTest() { | ||
StaticMember member = StaticMember.member(); | ||
|
||
// Warning when LHS is not able to be `null`. | ||
StaticMember memberLocal = .member() ?? member; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
StaticMember memberType = .memberType<String, int>("s") ?? member; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
void memberExtTest() { | ||
StaticMemberExt<int> member = StaticMemberExt.member(); | ||
|
||
// Warning when LHS is not able to be `null`. | ||
StaticMemberExt memberLocal = .member() ?? member; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
StaticMemberExt memberType = .memberType<String, int>("s") ?? member; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
tests/language/enum_shorthands/simple/simple_identifier_if_null_error_test.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// Copyright (c) 2024, 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. | ||
|
||
// Errors with `??` and enum shorthands with static properties or enums. | ||
|
||
// SharedOptions=--enable-experiment=enum-shorthands | ||
|
||
import '../enum_shorthand_helper.dart'; | ||
|
||
void test() { | ||
// Warning when LHS is not able to be `null`. | ||
Color colorLocal = .blue ?? Color.red; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
Integer integerLocal = .one ?? Integer.two; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
|
||
IntegerMixin integerMixinLocal = .mixinOne ?? IntegerMixin.mixinTwo; | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters