Skip to content

Commit 42a4442

Browse files
johnniwinthercommit-bot@chromium.org
authored andcommitted
[cfe] Handle promotion of Null to Never
Change-Id: If784cc315e0ea179e98df45a06d4a99179e4c197 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/127140 Reviewed-by: Dmitry Stefantsov <dmitryas@google.com> Commit-Queue: Johnni Winther <johnniwinther@google.com>
1 parent a9c7722 commit 42a4442

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

pkg/_fe_analyzer_shared/test/flow_analysis/type_promotion/data/null_check.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,11 @@ promotesNullableType(int? x) {
1717
x;
1818
}
1919
}
20+
21+
promotesNullType(Null x) {
22+
if (x != null) {
23+
/*Never*/ x;
24+
} else {
25+
x;
26+
}
27+
}

pkg/front_end/lib/src/fasta/type_inference/type_inference_engine.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import 'package:kernel/ast.dart'
1414
InterfaceType,
1515
Member,
1616
NamedType,
17+
NeverType,
1718
Nullability,
1819
TreeNode,
1920
TypeParameter,
@@ -267,6 +268,8 @@ class TypeOperationsCfe
267268
type.parameter, type.typeParameterTypeNullability, bound);
268269
}
269270
return type;
271+
} else if (type == typeEnvironment.nullType) {
272+
return const NeverType(Nullability.nonNullable);
270273
}
271274
return type.withNullability(Nullability.nonNullable);
272275
}

0 commit comments

Comments
 (0)