Skip to content

Commit ce7232c

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Store type Never in summaries.
[email protected], [email protected] Change-Id: I2b0e7cc86844caf2613a8c3e5ea00ce4576e6e8f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/109987 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 262e4c4 commit ce7232c

File tree

6 files changed

+46
-2
lines changed

6 files changed

+46
-2
lines changed

pkg/analyzer/lib/src/summary/resynthesize.dart

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,15 @@ class _UnitResynthesizer extends UnitResynthesizer with UnitResynthesizerMixin {
15591559
}
15601560
switch (linkedReference.kind) {
15611561
case ReferenceKind.classOrEnum:
1562-
element = new ClassElementHandle(summaryResynthesizer, location);
1562+
if (locationComponents.length == 3 &&
1563+
locationComponents[0] == 'dart:core' &&
1564+
locationComponents[1] == 'dart:core' &&
1565+
locationComponents[2] == 'Never') {
1566+
element = NeverElementImpl.instance;
1567+
type = BottomTypeImpl.instance;
1568+
} else {
1569+
element = new ClassElementHandle(summaryResynthesizer, location);
1570+
}
15631571
isDeclarableType = true;
15641572
break;
15651573
case ReferenceKind.constructor:

pkg/analyzer/lib/src/summary/summarize_ast.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,17 @@ class _SummarizeAstVisitor extends RecursiveAstVisitor {
516516
b.references = unlinkedReferences;
517517
b.typedefs = typedefs;
518518
b.variables = variables;
519+
519520
b.publicNamespace = computePublicNamespace(compilationUnit);
521+
if (isCoreLibrary) {
522+
b.publicNamespace.names.add(
523+
UnlinkedPublicNameBuilder(
524+
name: 'Never',
525+
kind: ReferenceKind.classOrEnum,
526+
),
527+
);
528+
}
529+
520530
_computeApiSignature(b);
521531
return b;
522532
}

pkg/analyzer/lib/src/summary2/linked_unit_context.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,8 @@ class LinkedUnitContext {
866866

867867
var kind = linkedType.kind;
868868
if (kind == LinkedNodeTypeKind.bottom) {
869-
return BottomTypeImpl.instance;
869+
var nullabilitySuffix = _nullabilitySuffix(linkedType.nullabilitySuffix);
870+
return BottomTypeImpl.instance.withNullability(nullabilitySuffix);
870871
} else if (kind == LinkedNodeTypeKind.dynamic_) {
871872
return DynamicTypeImpl.instance;
872873
} else if (kind == LinkedNodeTypeKind.function) {

pkg/analyzer/lib/src/summary2/linking_bundle_context.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ class LinkingBundleContext {
8080
if (type.isBottom) {
8181
return LinkedNodeTypeBuilder(
8282
kind: LinkedNodeTypeKind.bottom,
83+
nullabilitySuffix: _nullabilitySuffix(type),
8384
);
8485
} else if (type.isDynamic) {
8586
return LinkedNodeTypeBuilder(

pkg/analyzer/lib/src/summary2/named_type_builder.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class NamedTypeBuilder extends TypeBuilder {
8282
var substitution = Substitution.fromPairs(parameters, arguments);
8383
_type = substitution.substituteType(rawType);
8484
}
85+
} else if (element is NeverElementImpl) {
86+
_type = element.type.withNullability(nullabilitySuffix);
8587
} else if (element is TypeParameterElement) {
8688
_type = TypeParameterTypeImpl(element);
8789
} else {

pkg/analyzer/test/src/summary/resynthesize_common.dart

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9758,6 +9758,28 @@ dynamic v;
97589758
''');
97599759
}
97609760

9761+
test_type_never_disableNnbd() async {
9762+
featureSet = disableNnbd;
9763+
var library = await checkLibrary('Never d;');
9764+
checkElementText(
9765+
library,
9766+
r'''
9767+
Never* d;
9768+
''',
9769+
annotateNullability: true);
9770+
}
9771+
9772+
test_type_never_enableNnbd() async {
9773+
featureSet = enableNnbd;
9774+
var library = await checkLibrary('Never d;');
9775+
checkElementText(
9776+
library,
9777+
r'''
9778+
Never d;
9779+
''',
9780+
annotateNullability: true);
9781+
}
9782+
97619783
test_type_param_generic_function_type_nullability_legacy() async {
97629784
featureSet = disableNnbd;
97639785
var library = await checkLibrary('''

0 commit comments

Comments
 (0)