Skip to content

Commit 5cd6b30

Browse files
joshualittcommit-bot@chromium.org
authored andcommitted
[dart2js] Define type parameters of tearoffs as Object*/Object?
Change-Id: I5fa828b68e3dba398bac322a526af40616266ce5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/138102 Commit-Queue: Joshua Litt <joshualitt@google.com> Reviewed-by: Sigmund Cherem <sigmund@google.com>
1 parent ba6087f commit 5cd6b30

File tree

3 files changed

+30
-10
lines changed

3 files changed

+30
-10
lines changed

pkg/compiler/lib/src/elements/types.dart

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2117,4 +2117,22 @@ abstract class DartTypes {
21172117
DartType getTypeVariableBound(TypeVariableEntity element);
21182118

21192119
List<Variance> getTypeVariableVariances(ClassEntity cls);
2120+
2121+
DartType getTearOffParameterType(
2122+
DartType type, bool isCovariant, bool isNonNullableByDefaultLibrary) {
2123+
if (isCovariant) {
2124+
// A covariant parameter has type `Object` in the method signature.
2125+
var objectType = commonElements.objectType;
2126+
if (useNullSafety) {
2127+
if (isNonNullableByDefaultLibrary) {
2128+
return nullableType(objectType);
2129+
} else {
2130+
return legacyType(objectType);
2131+
}
2132+
} else {
2133+
return objectType;
2134+
}
2135+
}
2136+
return type;
2137+
}
21202138
}

pkg/compiler/lib/src/js_model/element_map_impl.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -870,11 +870,12 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap {
870870
List<DartType> optionalParameterTypes = <DartType>[];
871871

872872
DartType getParameterType(ir.VariableDeclaration variable) {
873-
if (variable.isCovariant || variable.isGenericCovariantImpl) {
874-
// A covariant parameter has type `Object` in the method signature.
875-
return commonElements.objectType;
876-
}
877-
return getDartType(variable.type);
873+
// isCovariant implies this FunctionNode is a class Procedure.
874+
var isCovariant = variable.isCovariant || variable.isGenericCovariantImpl;
875+
var isFromNonNullableByDefaultLibrary = isCovariant &&
876+
(node.parent as ir.Procedure).enclosingLibrary.isNonNullableByDefault;
877+
return types.getTearOffParameterType(getDartType(variable.type),
878+
isCovariant, isFromNonNullableByDefaultLibrary);
878879
}
879880

880881
for (ir.VariableDeclaration variable in node.positionalParameters) {

pkg/compiler/lib/src/kernel/element_map_impl.dart

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -493,11 +493,12 @@ class KernelToElementMapImpl implements KernelToElementMap, IrToElementMap {
493493
List<DartType> optionalParameterTypes = <DartType>[];
494494

495495
DartType getParameterType(ir.VariableDeclaration variable) {
496-
if (variable.isCovariant || variable.isGenericCovariantImpl) {
497-
// A covariant parameter has type `Object` in the method signature.
498-
return commonElements.objectType;
499-
}
500-
return getDartType(variable.type);
496+
// isCovariant implies this FunctionNode is a class Procedure.
497+
var isCovariant = variable.isCovariant || variable.isGenericCovariantImpl;
498+
var isFromNonNullableByDefaultLibrary = isCovariant &&
499+
(node.parent as ir.Procedure).enclosingLibrary.isNonNullableByDefault;
500+
return types.getTearOffParameterType(getDartType(variable.type),
501+
isCovariant, isFromNonNullableByDefaultLibrary);
501502
}
502503

503504
for (ir.VariableDeclaration variable in node.positionalParameters) {

0 commit comments

Comments
 (0)