Skip to content

Commit b817b1b

Browse files
johnniwintherCommit Queue
authored andcommitted
[cfe] Add test for exhaustiveness of != null
Change-Id: I04a34cf6f806a634a2290d8d3c68bbb724b7ebcc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/421183 Commit-Queue: Johnni Winther <[email protected]> Reviewed-by: Paul Berry <[email protected]>
1 parent eef9248 commit b817b1b

File tree

8 files changed

+135
-0
lines changed

8 files changed

+135
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
method(int? i) => /*
6+
checkingOrder={int?,int,Null},
7+
error=non-exhaustive:int();null,
8+
subtypes={int,Null},
9+
type=int?
10+
*/
11+
switch (i) {
12+
== null /*space=?*/ => null,
13+
!= null /*space=?*/ => i,
14+
};
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
method(int? i) => switch (i) {
6+
== null => null,
7+
!= null => i,
8+
_ => null,
9+
};
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
static method method(core::int? i) → dynamic
6+
return block {
7+
core::int? #t1;
8+
final synthesized core::int? #0#0 = i;
9+
synthesized core::bool #0#2;
10+
synthesized core::bool #0#2#isSet = false;
11+
#L1:
12+
{
13+
{
14+
if(#0#2#isSet ?{core::bool} #0#2{core::bool} : let final dynamic #t2 = #0#2#isSet = true in #0#2 = #0#0 == null) {
15+
#t1 = null;
16+
break #L1;
17+
}
18+
}
19+
{
20+
if(!(#0#2#isSet ?{core::bool} #0#2{core::bool} : let final dynamic #t3 = #0#2#isSet = true in #0#2 = #0#0{core::int} == null)) {
21+
#t1 = i{core::int};
22+
break #L1;
23+
}
24+
}
25+
{
26+
if(true) {
27+
#t1 = null;
28+
break #L1;
29+
}
30+
}
31+
}
32+
} =>#t1;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
static method method(core::int? i) → dynamic
6+
return block {
7+
core::int? #t1;
8+
final synthesized core::int? #0#0 = i;
9+
synthesized core::bool #0#2;
10+
synthesized core::bool #0#2#isSet = false;
11+
#L1:
12+
{
13+
{
14+
if(#0#2#isSet ?{core::bool} #0#2{core::bool} : let final dynamic #t2 = #0#2#isSet = true in #0#2 = #0#0 == null) {
15+
#t1 = null;
16+
break #L1;
17+
}
18+
}
19+
{
20+
if(!(#0#2#isSet ?{core::bool} #0#2{core::bool} : let final dynamic #t3 = #0#2#isSet = true in #0#2 = #0#0{core::int} == null)) {
21+
#t1 = i{core::int};
22+
break #L1;
23+
}
24+
}
25+
{
26+
if(true) {
27+
#t1 = null;
28+
break #L1;
29+
}
30+
}
31+
}
32+
} =>#t1;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
static method method(core::int? i) → dynamic
6+
;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
library;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
static method method(core::int? i) → dynamic
6+
return block {
7+
core::int? #t1;
8+
final synthesized core::int? #0#0 = i;
9+
synthesized core::bool #0#2;
10+
synthesized core::bool #0#2#isSet = false;
11+
#L1:
12+
{
13+
{
14+
if(#0#2#isSet ?{core::bool} #0#2{core::bool} : let final core::bool #t2 = #0#2#isSet = true in #0#2 = #0#0 == null) {
15+
#t1 = null;
16+
break #L1;
17+
}
18+
}
19+
{
20+
if(!(#0#2#isSet ?{core::bool} #0#2{core::bool} : let final core::bool #t3 = #0#2#isSet = true in #0#2 = #0#0{core::int} == null)) {
21+
#t1 = i{core::int};
22+
break #L1;
23+
}
24+
}
25+
{
26+
if(true) {
27+
#t1 = null;
28+
break #L1;
29+
}
30+
}
31+
}
32+
} =>#t1;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
method(int? i) => switch (i) {
2+
== null => null,
3+
!= null => i,
4+
_ => null,
5+
};
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
method(int? i) => switch (i) {
2+
== null => null,
3+
!= null => i,
4+
_ => null,
5+
};

0 commit comments

Comments
 (0)