Skip to content

Commit 723c856

Browse files
stereotype441Commit Queue
authored andcommitted
[analyzer] Rework InterfaceTypeImpl constructor to call NullTypeImpl
Previously, the `InterfaceTypeImpl._` constructor threw an exception if an interface type was being constructed for the type `Null` (because the `NullTypeImpl` constructor should be used instead). This was silly; as long as we're going to check, we might as well put the check in the `InterfaceTypeImpl` factory constructor, and have it simply construct the appropriate subtype. This is simpler, and should be much lower risk, since we no longer have a code path that has to throw an exception. Change-Id: Ie3ed216b285e371866a6a35ccccdf997b8a1f95e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/396620 Reviewed-by: Brian Wilkerson <[email protected]> Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Paul Berry <[email protected]>
1 parent f6e4b3e commit 723c856

File tree

3 files changed

+12
-27
lines changed

3 files changed

+12
-27
lines changed

pkg/analyzer/lib/src/dart/element/element.dart

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5913,16 +5913,11 @@ abstract class InterfaceElementImpl extends InstanceElementImpl
59135913
}
59145914
}
59155915

5916-
InterfaceTypeImpl result;
5917-
if (name == 'Null' && library.isDartCore) {
5918-
result = NullTypeImpl(element: this);
5919-
} else {
5920-
result = InterfaceTypeImpl(
5921-
element: this,
5922-
typeArguments: typeArguments,
5923-
nullabilitySuffix: nullabilitySuffix,
5924-
);
5925-
}
5916+
var result = InterfaceTypeImpl(
5917+
element: this,
5918+
typeArguments: typeArguments,
5919+
nullabilitySuffix: nullabilitySuffix,
5920+
);
59265921

59275922
if (typeArguments.isEmpty) {
59285923
switch (nullabilitySuffix) {
@@ -10283,11 +10278,6 @@ class TypeAliasElementImpl extends _ExistingElementImpl
1028310278
typeArguments: typeArguments,
1028410279
),
1028510280
);
10286-
} else if (type is NullTypeImpl) {
10287-
return NullTypeImpl(
10288-
element: type.element,
10289-
alias: InstantiatedTypeAliasElementImpl(
10290-
element: this, typeArguments: typeArguments));
1029110281
} else if (type is InterfaceType) {
1029210282
return InterfaceTypeImpl(
1029310283
element: type.element,

pkg/analyzer/lib/src/dart/element/type.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,8 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
534534
: InvalidTypeImpl.instance,
535535
nullabilitySuffix: nullabilitySuffix,
536536
alias: alias);
537+
} else if (element.name == 'Null' && element.library.isDartCore) {
538+
return NullTypeImpl(element: element, alias: alias);
537539
} else {
538540
return InterfaceTypeImpl._(
539541
element: element,
@@ -549,9 +551,6 @@ class InterfaceTypeImpl extends TypeImpl implements InterfaceType {
549551
required this.nullabilitySuffix,
550552
required super.alias,
551553
}) {
552-
if (element.name == 'Null' && element.library.isDartCore) {
553-
throw ArgumentError('NullTypeImpl should be used for `Null`');
554-
}
555554
if (element.augmentationTarget != null) {
556555
throw ArgumentError(
557556
'InterfaceType(s) can only be created for declarations',

pkg/analyzer/lib/src/dart/element/type_provider.dart

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -608,14 +608,10 @@ class TypeProviderImpl extends TypeProviderBase {
608608
}).toList(growable: false);
609609
}
610610

611-
if (element.name == 'Null' && element.library.isDartCore) {
612-
return NullTypeImpl(element: element);
613-
} else {
614-
return InterfaceTypeImpl(
615-
element: element,
616-
typeArguments: typeArguments,
617-
nullabilitySuffix: NullabilitySuffix.none,
618-
);
619-
}
611+
return InterfaceTypeImpl(
612+
element: element,
613+
typeArguments: typeArguments,
614+
nullabilitySuffix: NullabilitySuffix.none,
615+
);
620616
}
621617
}

0 commit comments

Comments
 (0)