Skip to content

Commit fa48659

Browse files
kallentuCommit Queue
authored andcommitted
[tests] Dot shorthands: Update bad language tests.
Updating some `??` tests to make them emit the correct warnings. Removed an expected error where there wasn't one. Bug: #59835 Change-Id: I8a1282e01ece6f3fd776eb06bcbb2cd7a1f8ed2a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/425587 Reviewed-by: Erik Ernst <[email protected]> Commit-Queue: Kallen Tu <[email protected]>
1 parent 24fbe71 commit fa48659

File tree

3 files changed

+51
-39
lines changed

3 files changed

+51
-39
lines changed

tests/language/dot_shorthands/constructor/constructor_if_null_error_test.dart

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,44 +8,52 @@
88

99
import '../dot_shorthand_helper.dart';
1010

11+
extension type IfNullConstructorExt(int x) implements num {
12+
IfNullConstructorExt.regular(this.x);
13+
IfNullConstructorExt.named({this.x = 1});
14+
IfNullConstructorExt.optional([this.x = 1]);
15+
}
16+
1117
void constructorClassTest() {
1218
ConstructorClass ctor = ConstructorClass(1);
1319

1420
// Warning when LHS is not able to be `null`.
1521
ConstructorClass notNullable = .new(1) ?? ctor;
16-
// ^
17-
// [analyzer] unspecified
22+
// ^^^^
23+
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
1824

1925
ConstructorClass notNullableRegular = .regular(1) ?? ctor;
20-
// ^
21-
// [analyzer] unspecified
26+
// ^^^^
27+
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
2228

2329
ConstructorClass notNullableNamed = .named(x: 1) ?? ctor;
24-
// ^
25-
// [analyzer] unspecified
30+
// ^^^^
31+
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
2632

2733
ConstructorClass notNullableOptional = .optional(1) ?? ctor;
28-
// ^
29-
// [analyzer] unspecified
34+
// ^^^^
35+
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
3036
}
3137

3238
void constructorExtTest() {
33-
ConstructorExt ctorExt = ConstructorExt(1);
39+
IfNullConstructorExt ctorExt = IfNullConstructorExt(1);
3440

3541
// Warning when LHS is not able to be `null`.
36-
ConstructorExt notNullableExt = .new(1) ?? ctorExt;
37-
// ^
38-
// [analyzer] unspecified
39-
40-
ConstructorExt notNullableRegularExt = .regular(1) ?? ctorExt;
41-
// ^
42-
// [analyzer] unspecified
43-
44-
ConstructorExt notNullableNamedExt = .named(x: 1) ?? ctorExt;
45-
// ^
46-
// [analyzer] unspecified
42+
IfNullConstructorExt notNullableExt = .new(1) ?? ctorExt;
43+
// ^^^^^^^
44+
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
45+
IfNullConstructorExt notNullableRegularExt = .regular(1) ?? ctorExt;
46+
// ^^^^^^^
47+
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
48+
IfNullConstructorExt notNullableNamedExt = .named(x: 1) ?? ctorExt;
49+
// ^^^^^^^
50+
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
51+
IfNullConstructorExt notNullableOptionalExt = .optional(1) ?? ctorExt;
52+
// ^^^^^^^
53+
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
54+
}
4755

48-
ConstructorExt notNullableOptionalExt = .optional(1) ?? ctorExt;
49-
// ^
50-
// [analyzer] unspecified
56+
void main() {
57+
constructorClassTest();
58+
constructorExtTest();
5159
}

tests/language/dot_shorthands/member/static_method_if_null_error_test.dart

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,28 +8,37 @@
88

99
import '../dot_shorthand_helper.dart';
1010

11+
extension type IfNullExt<T extends num>(T x) implements num {
12+
static IfNullExt<int> member() => IfNullExt(1);
13+
static IfNullExt<U> memberType<U extends num, V>(U u) => IfNullExt(u);
14+
}
15+
1116
void memberTest() {
1217
StaticMember member = StaticMember.member();
1318

1419
// Warning when LHS is not able to be `null`.
1520
StaticMember memberLocal = .member() ?? member;
16-
// ^
17-
// [analyzer] unspecified
21+
// ^^^^^^
22+
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
1823

1924
StaticMember memberType = .memberType<String, int>("s") ?? member;
20-
// ^
21-
// [analyzer] unspecified
25+
// ^^^^^^
26+
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
2227
}
2328

2429
void memberExtTest() {
25-
StaticMemberExt<int> member = StaticMemberExt.member();
30+
IfNullExt<int> member = IfNullExt.member();
2631

2732
// Warning when LHS is not able to be `null`.
28-
StaticMemberExt memberLocal = .member() ?? member;
29-
// ^
30-
// [analyzer] unspecified
33+
IfNullExt memberLocal = .member() ?? member;
34+
// ^^^^^^
35+
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
36+
IfNullExt memberType = .memberType<int, String>(1) ?? member;
37+
// ^^^^^^
38+
// [analyzer] STATIC_WARNING.DEAD_NULL_AWARE_EXPRESSION
39+
}
3140

32-
StaticMemberExt memberType = .memberType<String, int>("s") ?? member;
33-
// ^
34-
// [analyzer] unspecified
41+
void main() {
42+
memberTest();
43+
memberExtTest();
3544
}

tests/language/dot_shorthands/no_context/simple_identifier_no_context_error_test.dart

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ void main() async {
6565
// [analyzer] unspecified
6666
// [cfe] unspecified
6767

68-
map[.blue] = Color.red;
69-
// ^
70-
// [analyzer] unspecified
71-
// [cfe] unspecified
72-
7368
// Null assert.
7469
.one!;
7570
// ^

0 commit comments

Comments
 (0)