[cfe] Rename isCovariant and isGenericCovariantImpl
- to isCovariantByDeclaration and isCovariantByClass, respectively. This is done to align the terminology with the spec. TEST=existing Change-Id: I96b2e5d6e05caca431aad2b54545e928aee034e5 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213041 Commit-Queue: Johnni Winther <johnniwinther@google.com> Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
This commit is contained in:
committed by
commit-bot@chromium.org
parent
a82a2205aa
commit
d80cff6b2b
@@ -882,7 +882,8 @@ class JsKernelToElementMap implements JsToElementMap, IrToElementMap {
|
||||
|
||||
DartType getParameterType(ir.VariableDeclaration variable) {
|
||||
// isCovariant implies this FunctionNode is a class Procedure.
|
||||
var isCovariant = variable.isCovariant || variable.isGenericCovariantImpl;
|
||||
var isCovariant =
|
||||
variable.isCovariantByDeclaration || variable.isCovariantByClass;
|
||||
var isFromNonNullableByDefaultLibrary = isCovariant &&
|
||||
(node.parent as ir.Procedure).enclosingLibrary.isNonNullableByDefault;
|
||||
return types.getTearOffParameterType(getDartType(variable.type),
|
||||
|
||||
@@ -518,7 +518,8 @@ class KernelToElementMapImpl implements KernelToElementMap, IrToElementMap {
|
||||
|
||||
DartType getParameterType(ir.VariableDeclaration variable) {
|
||||
// isCovariant implies this FunctionNode is a class Procedure.
|
||||
var isCovariant = variable.isCovariant || variable.isGenericCovariantImpl;
|
||||
var isCovariant =
|
||||
variable.isCovariantByDeclaration || variable.isCovariantByClass;
|
||||
var isFromNonNullableByDefaultLibrary = isCovariant &&
|
||||
(node.parent as ir.Procedure).enclosingLibrary.isNonNullableByDefault;
|
||||
return types.getTearOffParameterType(getDartType(variable.type),
|
||||
|
||||
@@ -1409,7 +1409,7 @@ class KernelSsaGraphBuilder extends ir.Visitor<void> with ir.VisitorVoidMixin {
|
||||
|
||||
if (targetChecks.checkAllParameters ||
|
||||
(targetChecks.checkCovariantParameters &&
|
||||
(variable.isGenericCovariantImpl || variable.isCovariant))) {
|
||||
(variable.isCovariantByClass || variable.isCovariantByDeclaration))) {
|
||||
newParameter = _typeBuilder.potentiallyCheckOrTrustTypeOfParameter(
|
||||
targetElement, newParameter, type);
|
||||
} else {
|
||||
|
||||
@@ -3719,7 +3719,7 @@ class ProgramCompiler extends ComputeOnceConstantVisitor<js_ast.Expression>
|
||||
void _emitCovarianceBoundsCheck(
|
||||
List<TypeParameter> typeFormals, List<js_ast.Statement> body) {
|
||||
for (var t in typeFormals) {
|
||||
if (t.isGenericCovariantImpl && !_types.isTop(t.bound)) {
|
||||
if (t.isCovariantByClass && !_types.isTop(t.bound)) {
|
||||
body.add(runtimeStatement('checkTypeBound(#, #, #)', [
|
||||
_emitTypeParameterType(TypeParameterType(t, Nullability.undetermined),
|
||||
emitNullability: false),
|
||||
|
||||
@@ -211,13 +211,13 @@ bool isInlineJS(Member e) =>
|
||||
/// Whether the parameter [p] is covariant (either explicitly `covariant` or
|
||||
/// implicitly due to generics) and needs a check for soundness.
|
||||
bool isCovariantParameter(VariableDeclaration p) {
|
||||
return p.isCovariant || p.isGenericCovariantImpl;
|
||||
return p.isCovariantByDeclaration || p.isCovariantByClass;
|
||||
}
|
||||
|
||||
/// Whether the field [p] is covariant (either explicitly `covariant` or
|
||||
/// implicitly due to generics) and needs a check for soundness.
|
||||
bool isCovariantField(Field f) {
|
||||
return f.isCovariant || f.isGenericCovariantImpl;
|
||||
return f.isCovariantByDeclaration || f.isCovariantByClass;
|
||||
}
|
||||
|
||||
/// Returns true iff this factory constructor just throws [UnsupportedError]/
|
||||
|
||||
@@ -273,8 +273,8 @@ class ClassPropertyModel {
|
||||
var name = field.name.text;
|
||||
if (virtualAccessorNames.contains(name) ||
|
||||
fieldModel.isVirtual(field) ||
|
||||
field.isCovariant ||
|
||||
field.isGenericCovariantImpl) {
|
||||
field.isCovariantByDeclaration ||
|
||||
field.isCovariantByClass) {
|
||||
virtualFields[field] = js_ast.TemporaryId(js_ast.toJSIdentifier(name));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -276,14 +276,15 @@ class _CovarianceTransformer extends RecursiveVisitor {
|
||||
|
||||
_CovarianceTransformer(this._library);
|
||||
|
||||
/// Transforms [_library], eliminating unncessary checks for private members.
|
||||
/// Transforms [_library], eliminating unnecessary checks for private members.
|
||||
///
|
||||
/// Kernel will mark covariance checks on members, for example:
|
||||
/// - a field with [Field.isGenericCovariantImpl] or [Field.isCovariant].
|
||||
/// - a field with [Field.isCovariantByClass] or
|
||||
/// [Field.isCovariantByDeclaration].
|
||||
/// - a method/setter with parameter(s) or type parameter(s) that have
|
||||
/// `isGenericCovariantImpl` or `isCovariant` set.
|
||||
/// `isCovariantByClass` or `isCovariantByDeclaration` set.
|
||||
///
|
||||
/// If the check can be safely eliminanted, those properties will be set to
|
||||
/// If the check can be safely eliminated, those properties will be set to
|
||||
/// false so the JS compiler does not emit checks.
|
||||
///
|
||||
/// Public members always need covariance checks (we cannot see all potential
|
||||
@@ -319,13 +320,13 @@ class _CovarianceTransformer extends RecursiveVisitor {
|
||||
// Update the tree based on the methods that need checks.
|
||||
for (var field in _privateFields) {
|
||||
if (!_checkedMembers.contains(field)) {
|
||||
field.isCovariant = false;
|
||||
field.isGenericCovariantImpl = false;
|
||||
field.isCovariantByDeclaration = false;
|
||||
field.isCovariantByClass = false;
|
||||
}
|
||||
}
|
||||
void clearCovariant(VariableDeclaration parameter) {
|
||||
parameter.isCovariant = false;
|
||||
parameter.isGenericCovariantImpl = false;
|
||||
parameter.isCovariantByDeclaration = false;
|
||||
parameter.isCovariantByClass = false;
|
||||
}
|
||||
|
||||
for (var member in _privateProcedures) {
|
||||
@@ -334,7 +335,7 @@ class _CovarianceTransformer extends RecursiveVisitor {
|
||||
function.positionalParameters.forEach(clearCovariant);
|
||||
function.namedParameters.forEach(clearCovariant);
|
||||
for (var t in function.typeParameters) {
|
||||
t.isGenericCovariantImpl = false;
|
||||
t.isCovariantByClass = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ abstract class FieldBuilder implements MemberBuilder {
|
||||
|
||||
TypeBuilder? get type;
|
||||
|
||||
bool get isCovariant;
|
||||
bool get isCovariantByDeclaration;
|
||||
|
||||
bool get isLate;
|
||||
|
||||
@@ -154,7 +154,7 @@ class SourceFieldBuilder extends MemberBuilderImpl implements FieldBuilder {
|
||||
isAbstract: isAbstract,
|
||||
isExternal: isExternal,
|
||||
isFinal: isFinal,
|
||||
isCovariant: isCovariant,
|
||||
isCovariantByDeclaration: isCovariantByDeclaration,
|
||||
isNonNullableByDefault: library.isNonNullableByDefault);
|
||||
} else if (isLate &&
|
||||
libraryBuilder.loader.target.backendTarget.isLateFieldLoweringEnabled(
|
||||
@@ -175,7 +175,7 @@ class SourceFieldBuilder extends MemberBuilderImpl implements FieldBuilder {
|
||||
lateIsSetSetterReference,
|
||||
lateGetterReference,
|
||||
lateSetterReference,
|
||||
isCovariant,
|
||||
isCovariantByDeclaration,
|
||||
isSetStrategy);
|
||||
} else {
|
||||
_fieldEncoding = new LateFieldWithInitializerEncoding(
|
||||
@@ -190,7 +190,7 @@ class SourceFieldBuilder extends MemberBuilderImpl implements FieldBuilder {
|
||||
lateIsSetSetterReference,
|
||||
lateGetterReference,
|
||||
lateSetterReference,
|
||||
isCovariant,
|
||||
isCovariantByDeclaration,
|
||||
isSetStrategy);
|
||||
}
|
||||
} else {
|
||||
@@ -207,7 +207,7 @@ class SourceFieldBuilder extends MemberBuilderImpl implements FieldBuilder {
|
||||
lateIsSetSetterReference,
|
||||
lateGetterReference,
|
||||
lateSetterReference,
|
||||
isCovariant,
|
||||
isCovariantByDeclaration,
|
||||
isSetStrategy);
|
||||
} else {
|
||||
_fieldEncoding = new LateFieldWithoutInitializerEncoding(
|
||||
@@ -222,7 +222,7 @@ class SourceFieldBuilder extends MemberBuilderImpl implements FieldBuilder {
|
||||
lateIsSetSetterReference,
|
||||
lateGetterReference,
|
||||
lateSetterReference,
|
||||
isCovariant,
|
||||
isCovariantByDeclaration,
|
||||
isSetStrategy);
|
||||
}
|
||||
}
|
||||
@@ -244,7 +244,7 @@ class SourceFieldBuilder extends MemberBuilderImpl implements FieldBuilder {
|
||||
lateIsSetSetterReference,
|
||||
lateGetterReference,
|
||||
lateSetterReference,
|
||||
isCovariant,
|
||||
isCovariantByDeclaration,
|
||||
isSetStrategy);
|
||||
} else {
|
||||
_fieldEncoding = new LateFieldWithInitializerEncoding(
|
||||
@@ -259,7 +259,7 @@ class SourceFieldBuilder extends MemberBuilderImpl implements FieldBuilder {
|
||||
lateIsSetSetterReference,
|
||||
lateGetterReference,
|
||||
lateSetterReference,
|
||||
isCovariant,
|
||||
isCovariantByDeclaration,
|
||||
isSetStrategy);
|
||||
}
|
||||
} else {
|
||||
@@ -320,7 +320,7 @@ class SourceFieldBuilder extends MemberBuilderImpl implements FieldBuilder {
|
||||
bool get isLate => (modifiers & lateMask) != 0;
|
||||
|
||||
@override
|
||||
bool get isCovariant => (modifiers & covariantMask) != 0;
|
||||
bool get isCovariantByDeclaration => (modifiers & covariantMask) != 0;
|
||||
|
||||
@override
|
||||
bool get hasInitializer => (modifiers & hasInitializerMask) != 0;
|
||||
@@ -665,7 +665,7 @@ class RegularFieldEncoding implements FieldEncoding {
|
||||
@override
|
||||
void build(
|
||||
SourceLibraryBuilder libraryBuilder, SourceFieldBuilder fieldBuilder) {
|
||||
_field..isCovariant = fieldBuilder.isCovariant;
|
||||
_field..isCovariantByDeclaration = fieldBuilder.isCovariantByDeclaration;
|
||||
if (fieldBuilder.isExtensionMember) {
|
||||
_field
|
||||
..isStatic = true
|
||||
@@ -695,7 +695,7 @@ class RegularFieldEncoding implements FieldEncoding {
|
||||
|
||||
@override
|
||||
void setGenericCovariantImpl() {
|
||||
_field.isGenericCovariantImpl = true;
|
||||
_field.isCovariantByClass = true;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -814,7 +814,7 @@ abstract class AbstractLateFieldEncoding implements FieldEncoding {
|
||||
Reference? lateIsSetSetterReference,
|
||||
Reference? lateGetterReference,
|
||||
Reference? lateSetterReference,
|
||||
bool isCovariant,
|
||||
bool isCovariantByDeclaration,
|
||||
late_lowering.IsSetStrategy isSetStrategy)
|
||||
: fileOffset = charOffset,
|
||||
fileEndOffset = charEndOffset,
|
||||
@@ -867,7 +867,7 @@ abstract class AbstractLateFieldEncoding implements FieldEncoding {
|
||||
fileUri,
|
||||
charOffset,
|
||||
lateSetterReference,
|
||||
isCovariant: isCovariant);
|
||||
isCovariantByDeclaration: isCovariantByDeclaration);
|
||||
}
|
||||
|
||||
late_lowering.IsSetEncoding get isSetEncoding {
|
||||
@@ -975,11 +975,11 @@ abstract class AbstractLateFieldEncoding implements FieldEncoding {
|
||||
|
||||
Procedure? _createSetter(
|
||||
Name name, Uri fileUri, int charOffset, Reference? reference,
|
||||
{required bool isCovariant}) {
|
||||
{required bool isCovariantByDeclaration}) {
|
||||
// ignore: unnecessary_null_comparison
|
||||
assert(isCovariant != null);
|
||||
assert(isCovariantByDeclaration != null);
|
||||
VariableDeclaration parameter = new VariableDeclaration(null)
|
||||
..isCovariant = isCovariant
|
||||
..isCovariantByDeclaration = isCovariantByDeclaration
|
||||
..fileOffset = fileOffset;
|
||||
return new Procedure(
|
||||
name,
|
||||
@@ -1025,9 +1025,8 @@ abstract class AbstractLateFieldEncoding implements FieldEncoding {
|
||||
|
||||
@override
|
||||
void setGenericCovariantImpl() {
|
||||
_field.isGenericCovariantImpl = true;
|
||||
_lateSetter?.function.positionalParameters.single.isGenericCovariantImpl =
|
||||
true;
|
||||
_field.isCovariantByClass = true;
|
||||
_lateSetter?.function.positionalParameters.single.isCovariantByClass = true;
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -1198,7 +1197,7 @@ class LateFieldWithoutInitializerEncoding extends AbstractLateFieldEncoding
|
||||
Reference? lateIsSetSetterReference,
|
||||
Reference? lateGetterReference,
|
||||
Reference? lateSetterReference,
|
||||
bool isCovariant,
|
||||
bool isCovariantByDeclaration,
|
||||
late_lowering.IsSetStrategy isSetStrategy)
|
||||
: super(
|
||||
name,
|
||||
@@ -1212,7 +1211,7 @@ class LateFieldWithoutInitializerEncoding extends AbstractLateFieldEncoding
|
||||
lateIsSetSetterReference,
|
||||
lateGetterReference,
|
||||
lateSetterReference,
|
||||
isCovariant,
|
||||
isCovariantByDeclaration,
|
||||
isSetStrategy);
|
||||
}
|
||||
|
||||
@@ -1230,7 +1229,7 @@ class LateFieldWithInitializerEncoding extends AbstractLateFieldEncoding
|
||||
Reference? lateIsSetSetterReference,
|
||||
Reference? lateGetterReference,
|
||||
Reference? lateSetterReference,
|
||||
bool isCovariant,
|
||||
bool isCovariantByDeclaration,
|
||||
late_lowering.IsSetStrategy isSetStrategy)
|
||||
: super(
|
||||
name,
|
||||
@@ -1244,7 +1243,7 @@ class LateFieldWithInitializerEncoding extends AbstractLateFieldEncoding
|
||||
lateIsSetSetterReference,
|
||||
lateGetterReference,
|
||||
lateSetterReference,
|
||||
isCovariant,
|
||||
isCovariantByDeclaration,
|
||||
isSetStrategy);
|
||||
|
||||
@override
|
||||
@@ -1277,7 +1276,7 @@ class LateFinalFieldWithoutInitializerEncoding extends AbstractLateFieldEncoding
|
||||
Reference? lateIsSetSetterReference,
|
||||
Reference? lateGetterReference,
|
||||
Reference? lateSetterReference,
|
||||
bool isCovariant,
|
||||
bool isCovariantByDeclaration,
|
||||
late_lowering.IsSetStrategy isSetStrategy)
|
||||
: super(
|
||||
name,
|
||||
@@ -1291,7 +1290,7 @@ class LateFinalFieldWithoutInitializerEncoding extends AbstractLateFieldEncoding
|
||||
lateIsSetSetterReference,
|
||||
lateGetterReference,
|
||||
lateSetterReference,
|
||||
isCovariant,
|
||||
isCovariantByDeclaration,
|
||||
isSetStrategy);
|
||||
|
||||
@override
|
||||
@@ -1325,7 +1324,7 @@ class LateFinalFieldWithInitializerEncoding extends AbstractLateFieldEncoding {
|
||||
Reference? lateIsSetSetterReference,
|
||||
Reference? lateGetterReference,
|
||||
Reference? lateSetterReference,
|
||||
bool isCovariant,
|
||||
bool isCovariantByDeclaration,
|
||||
late_lowering.IsSetStrategy isSetStrategy)
|
||||
: super(
|
||||
name,
|
||||
@@ -1339,7 +1338,7 @@ class LateFinalFieldWithInitializerEncoding extends AbstractLateFieldEncoding {
|
||||
lateIsSetSetterReference,
|
||||
lateGetterReference,
|
||||
lateSetterReference,
|
||||
isCovariant,
|
||||
isCovariantByDeclaration,
|
||||
isSetStrategy);
|
||||
@override
|
||||
Statement _createGetterBody(
|
||||
@@ -1360,7 +1359,7 @@ class LateFinalFieldWithInitializerEncoding extends AbstractLateFieldEncoding {
|
||||
@override
|
||||
Procedure? _createSetter(
|
||||
Name name, Uri fileUri, int charOffset, Reference? reference,
|
||||
{required bool isCovariant}) =>
|
||||
{required bool isCovariantByDeclaration}) =>
|
||||
null;
|
||||
|
||||
@override
|
||||
@@ -1537,7 +1536,7 @@ class AbstractOrExternalFieldEncoding implements FieldEncoding {
|
||||
{required this.isAbstract,
|
||||
required this.isExternal,
|
||||
required bool isFinal,
|
||||
required bool isCovariant,
|
||||
required bool isCovariantByDeclaration,
|
||||
required bool isNonNullableByDefault})
|
||||
// ignore: unnecessary_null_comparison
|
||||
: assert(isAbstract != null),
|
||||
@@ -1546,7 +1545,7 @@ class AbstractOrExternalFieldEncoding implements FieldEncoding {
|
||||
// ignore: unnecessary_null_comparison
|
||||
assert(isFinal != null),
|
||||
// ignore: unnecessary_null_comparison
|
||||
assert(isCovariant != null),
|
||||
assert(isCovariantByDeclaration != null),
|
||||
// ignore: unnecessary_null_comparison
|
||||
assert(isNonNullableByDefault != null),
|
||||
_isExtensionInstanceMember = isExternal &&
|
||||
@@ -1567,7 +1566,7 @@ class AbstractOrExternalFieldEncoding implements FieldEncoding {
|
||||
if (!isFinal) {
|
||||
VariableDeclaration parameter =
|
||||
new VariableDeclaration("#externalFieldValue")
|
||||
..isCovariant = isCovariant
|
||||
..isCovariantByDeclaration = isCovariantByDeclaration
|
||||
..fileOffset = charOffset;
|
||||
_setter = new Procedure(
|
||||
nameScheme.getProcedureName(ProcedureKind.Setter, name),
|
||||
@@ -1600,7 +1599,7 @@ class AbstractOrExternalFieldEncoding implements FieldEncoding {
|
||||
if (!isFinal) {
|
||||
VariableDeclaration parameter =
|
||||
new VariableDeclaration("#externalFieldValue")
|
||||
..isCovariant = isCovariant
|
||||
..isCovariantByDeclaration = isCovariantByDeclaration
|
||||
..fileOffset = charOffset;
|
||||
_setter = new Procedure(
|
||||
nameScheme.getFieldName(FieldNameType.Setter, name,
|
||||
@@ -1742,7 +1741,7 @@ class AbstractOrExternalFieldEncoding implements FieldEncoding {
|
||||
|
||||
@override
|
||||
void setGenericCovariantImpl() {
|
||||
_setter!.function.positionalParameters.first.isGenericCovariantImpl = true;
|
||||
_setter!.function.positionalParameters.first.isCovariantByClass = true;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -116,7 +116,7 @@ class FormalParameterBuilder extends ModifierBuilderImpl
|
||||
|
||||
bool get isInitializingFormal => (modifiers & initializingFormalMask) != 0;
|
||||
|
||||
bool get isCovariant => (modifiers & covariantMask) != 0;
|
||||
bool get isCovariantByDeclaration => (modifiers & covariantMask) != 0;
|
||||
|
||||
// An initializing formal parameter might be final without its
|
||||
// VariableDeclaration being final. See
|
||||
@@ -142,7 +142,7 @@ class FormalParameterBuilder extends ModifierBuilderImpl
|
||||
isFinal: isFinal,
|
||||
isConst: isConst,
|
||||
isFieldFormal: isInitializingFormal,
|
||||
isCovariant: isCovariant,
|
||||
isCovariantByDeclaration: isCovariantByDeclaration,
|
||||
isRequired: isNamedRequired,
|
||||
hasDeclaredInitializer: hasDeclaredInitializer,
|
||||
isLowered: isExtensionThis)
|
||||
|
||||
@@ -346,7 +346,7 @@ abstract class FunctionBuilderImpl extends MemberBuilderImpl
|
||||
function.typeParameters.add(parameter);
|
||||
if (needsCheckVisitor != null) {
|
||||
if (parameter.bound.accept(needsCheckVisitor)) {
|
||||
parameter.isGenericCovariantImpl = true;
|
||||
parameter.isCovariantByClass = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -358,7 +358,7 @@ abstract class FunctionBuilderImpl extends MemberBuilderImpl
|
||||
nonInstanceContext: !isConstructor && !isDeclarationInstanceMember);
|
||||
if (needsCheckVisitor != null) {
|
||||
if (parameter.type.accept(needsCheckVisitor)) {
|
||||
parameter.isGenericCovariantImpl = true;
|
||||
parameter.isCovariantByClass = true;
|
||||
}
|
||||
}
|
||||
if (formal.isNamed) {
|
||||
|
||||
@@ -422,7 +422,9 @@ bool hasSameSignature(FunctionNode a, FunctionNode b) {
|
||||
List<TypeParameter> aTypeParameters = a.typeParameters;
|
||||
List<TypeParameter> bTypeParameters = b.typeParameters;
|
||||
int typeParameterCount = aTypeParameters.length;
|
||||
if (typeParameterCount != bTypeParameters.length) return false;
|
||||
if (typeParameterCount != bTypeParameters.length) {
|
||||
return false;
|
||||
}
|
||||
Substitution? substitution;
|
||||
if (typeParameterCount != 0) {
|
||||
List<DartType> types = new List<DartType>.generate(
|
||||
@@ -434,11 +436,15 @@ bool hasSameSignature(FunctionNode a, FunctionNode b) {
|
||||
for (int i = 0; i < typeParameterCount; i++) {
|
||||
DartType aBound = aTypeParameters[i].bound;
|
||||
DartType bBound = substitution.substituteType(bTypeParameters[i].bound);
|
||||
if (aBound != bBound) return false;
|
||||
if (aBound != bBound) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (a.requiredParameterCount != b.requiredParameterCount) return false;
|
||||
if (a.requiredParameterCount != b.requiredParameterCount) {
|
||||
return false;
|
||||
}
|
||||
List<VariableDeclaration> aPositionalParameters = a.positionalParameters;
|
||||
List<VariableDeclaration> bPositionalParameters = b.positionalParameters;
|
||||
if (aPositionalParameters.length != bPositionalParameters.length) {
|
||||
@@ -447,7 +453,10 @@ bool hasSameSignature(FunctionNode a, FunctionNode b) {
|
||||
for (int i = 0; i < aPositionalParameters.length; i++) {
|
||||
VariableDeclaration aParameter = aPositionalParameters[i];
|
||||
VariableDeclaration bParameter = bPositionalParameters[i];
|
||||
if (aParameter.isCovariant != bParameter.isCovariant) return false;
|
||||
if (aParameter.isCovariantByDeclaration !=
|
||||
bParameter.isCovariantByDeclaration) {
|
||||
return false;
|
||||
}
|
||||
DartType aType = aParameter.type;
|
||||
DartType bType = bParameter.type;
|
||||
if (substitution != null) {
|
||||
@@ -458,18 +467,27 @@ bool hasSameSignature(FunctionNode a, FunctionNode b) {
|
||||
|
||||
List<VariableDeclaration> aNamedParameters = a.namedParameters;
|
||||
List<VariableDeclaration> bNamedParameters = b.namedParameters;
|
||||
if (aNamedParameters.length != bNamedParameters.length) return false;
|
||||
if (aNamedParameters.length != bNamedParameters.length) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 0; i < aNamedParameters.length; i++) {
|
||||
VariableDeclaration aParameter = aNamedParameters[i];
|
||||
VariableDeclaration bParameter = bNamedParameters[i];
|
||||
if (aParameter.isCovariant != bParameter.isCovariant) return false;
|
||||
if (aParameter.name != bParameter.name) return false;
|
||||
if (aParameter.isCovariantByDeclaration !=
|
||||
bParameter.isCovariantByDeclaration) {
|
||||
return false;
|
||||
}
|
||||
if (aParameter.name != bParameter.name) {
|
||||
return false;
|
||||
}
|
||||
DartType aType = aParameter.type;
|
||||
DartType bType = bParameter.type;
|
||||
if (substitution != null) {
|
||||
bType = substitution.substituteType(bType);
|
||||
}
|
||||
if (aType != bType) return false;
|
||||
if (aType != bType) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
DartType aReturnType = a.returnType;
|
||||
|
||||
@@ -483,8 +483,8 @@ abstract class CombinedMemberSignatureBase<T> {
|
||||
member.function.positionalParameters.first;
|
||||
combinedMemberSignature = _createSetterMemberSignature(
|
||||
member, combinedMemberSignatureType!,
|
||||
isGenericCovariantImpl: parameter.isGenericCovariantImpl,
|
||||
isCovariant: parameter.isCovariant,
|
||||
isCovariantByClass: parameter.isCovariantByClass,
|
||||
isCovariantByDeclaration: parameter.isCovariantByDeclaration,
|
||||
parameter: parameter,
|
||||
copyLocation: copyLocation);
|
||||
break;
|
||||
@@ -503,8 +503,8 @@ abstract class CombinedMemberSignatureBase<T> {
|
||||
if (forSetter) {
|
||||
combinedMemberSignature = _createSetterMemberSignature(
|
||||
member, combinedMemberSignatureType!,
|
||||
isGenericCovariantImpl: member.isGenericCovariantImpl,
|
||||
isCovariant: member.isCovariant,
|
||||
isCovariantByClass: member.isCovariantByClass,
|
||||
isCovariantByDeclaration: member.isCovariantByDeclaration,
|
||||
copyLocation: copyLocation);
|
||||
} else {
|
||||
combinedMemberSignature = _createGetterMemberSignature(
|
||||
@@ -559,17 +559,18 @@ abstract class CombinedMemberSignatureBase<T> {
|
||||
}
|
||||
|
||||
/// Creates a setter member signature for [member] with the given
|
||||
/// [type]. The flags of parameter is set according to [isCovariant] and
|
||||
/// [isGenericCovariantImpl] and the [parameterName] is used, if provided.
|
||||
/// [type]. The flags of parameter is set according to
|
||||
/// [isCovariantByDeclaration] and [isCovariantByClass] and the name of the
|
||||
/// [parameter] is used, if provided.
|
||||
Procedure _createSetterMemberSignature(Member member, DartType type,
|
||||
{required bool isCovariant,
|
||||
required bool isGenericCovariantImpl,
|
||||
{required bool isCovariantByDeclaration,
|
||||
required bool isCovariantByClass,
|
||||
VariableDeclaration? parameter,
|
||||
required bool copyLocation}) {
|
||||
// ignore: unnecessary_null_comparison
|
||||
assert(isCovariant != null);
|
||||
assert(isCovariantByDeclaration != null);
|
||||
// ignore: unnecessary_null_comparison
|
||||
assert(isGenericCovariantImpl != null);
|
||||
assert(isCovariantByClass != null);
|
||||
// ignore: unnecessary_null_comparison
|
||||
assert(copyLocation != null);
|
||||
Class enclosingClass = classBuilder.cls;
|
||||
@@ -594,8 +595,8 @@ abstract class CombinedMemberSignatureBase<T> {
|
||||
returnType: const VoidType(),
|
||||
positionalParameters: [
|
||||
new VariableDeclaration(parameter?.name ?? 'value',
|
||||
type: type, isCovariant: isCovariant)
|
||||
..isGenericCovariantImpl = isGenericCovariantImpl
|
||||
type: type, isCovariantByDeclaration: isCovariantByDeclaration)
|
||||
..isCovariantByClass = isCovariantByClass
|
||||
..fileOffset = copyLocation
|
||||
? parameter?.fileOffset ?? fileOffset
|
||||
: fileOffset
|
||||
@@ -638,8 +639,9 @@ abstract class CombinedMemberSignatureBase<T> {
|
||||
VariableDeclaration parameter = function.positionalParameters[i];
|
||||
DartType parameterType = functionType.positionalParameters[i];
|
||||
positionalParameters.add(new VariableDeclaration(parameter.name,
|
||||
type: parameterType, isCovariant: parameter.isCovariant)
|
||||
..isGenericCovariantImpl = parameter.isGenericCovariantImpl
|
||||
type: parameterType,
|
||||
isCovariantByDeclaration: parameter.isCovariantByDeclaration)
|
||||
..isCovariantByClass = parameter.isCovariantByClass
|
||||
..fileOffset = copyLocation ? parameter.fileOffset : fileOffset);
|
||||
}
|
||||
List<VariableDeclaration> namedParameters = [];
|
||||
@@ -650,8 +652,8 @@ abstract class CombinedMemberSignatureBase<T> {
|
||||
namedParameters.add(new VariableDeclaration(parameter.name,
|
||||
type: namedType.type,
|
||||
isRequired: namedType.isRequired,
|
||||
isCovariant: parameter.isCovariant)
|
||||
..isGenericCovariantImpl = parameter.isGenericCovariantImpl
|
||||
isCovariantByDeclaration: parameter.isCovariantByDeclaration)
|
||||
..isCovariantByClass = parameter.isCovariantByClass
|
||||
..fileOffset = copyLocation ? parameter.fileOffset : fileOffset);
|
||||
} else if (namedParameterCount > 1) {
|
||||
Map<String, NamedType> namedTypes = {};
|
||||
@@ -664,8 +666,8 @@ abstract class CombinedMemberSignatureBase<T> {
|
||||
namedParameters.add(new VariableDeclaration(parameter.name,
|
||||
type: namedParameterType.type,
|
||||
isRequired: namedParameterType.isRequired,
|
||||
isCovariant: parameter.isCovariant)
|
||||
..isGenericCovariantImpl = parameter.isGenericCovariantImpl
|
||||
isCovariantByDeclaration: parameter.isCovariantByDeclaration)
|
||||
..isCovariantByClass = parameter.isCovariantByClass
|
||||
..fileOffset = copyLocation ? parameter.fileOffset : fileOffset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -645,7 +645,7 @@ class Forest {
|
||||
bool isFinal: false,
|
||||
bool isConst: false,
|
||||
bool isFieldFormal: false,
|
||||
bool isCovariant: false,
|
||||
bool isCovariantByDeclaration: false,
|
||||
bool isLocalFunction: false}) {
|
||||
// ignore: unnecessary_null_comparison
|
||||
assert(fileOffset != null);
|
||||
@@ -655,7 +655,7 @@ class Forest {
|
||||
isFinal: isFinal,
|
||||
isConst: isConst,
|
||||
isFieldFormal: isFieldFormal,
|
||||
isCovariant: isCovariant,
|
||||
isCovariantByDeclaration: isCovariantByDeclaration,
|
||||
isLocalFunction: isLocalFunction,
|
||||
hasDeclaredInitializer: initializer != null);
|
||||
}
|
||||
|
||||
@@ -1592,7 +1592,7 @@ class VariableDeclarationImpl extends VariableDeclaration {
|
||||
bool isFinal: false,
|
||||
bool isConst: false,
|
||||
bool isFieldFormal: false,
|
||||
bool isCovariant: false,
|
||||
bool isCovariantByDeclaration: false,
|
||||
bool isLocalFunction: false,
|
||||
bool isLate: false,
|
||||
bool isRequired: false,
|
||||
@@ -1606,7 +1606,7 @@ class VariableDeclarationImpl extends VariableDeclaration {
|
||||
isFinal: isFinal,
|
||||
isConst: isConst,
|
||||
isFieldFormal: isFieldFormal,
|
||||
isCovariant: isCovariant,
|
||||
isCovariantByDeclaration: isCovariantByDeclaration,
|
||||
isLate: isLate,
|
||||
isRequired: isRequired,
|
||||
isLowered: isLowered);
|
||||
|
||||
@@ -17,32 +17,32 @@ class Covariance {
|
||||
|
||||
/// Returns the covariance mask for [parameter].
|
||||
static int covarianceFromParameter(VariableDeclaration parameter) =>
|
||||
(parameter.isCovariant ? Covariant : 0) |
|
||||
(parameter.isGenericCovariantImpl ? GenericCovariantImpl : 0);
|
||||
(parameter.isCovariantByDeclaration ? Covariant : 0) |
|
||||
(parameter.isCovariantByClass ? GenericCovariantImpl : 0);
|
||||
|
||||
/// Returns the covariance mask for [field].
|
||||
static int covarianceFromField(Field field) =>
|
||||
(field.isCovariant ? Covariant : 0) |
|
||||
(field.isGenericCovariantImpl ? GenericCovariantImpl : 0);
|
||||
(field.isCovariantByDeclaration ? Covariant : 0) |
|
||||
(field.isCovariantByClass ? GenericCovariantImpl : 0);
|
||||
|
||||
/// Applies the [covariance] mask to [parameter].
|
||||
static void covarianceToParameter(
|
||||
int covariance, VariableDeclaration parameter) {
|
||||
if ((covariance & Covariant) != 0) {
|
||||
parameter.isCovariant = true;
|
||||
parameter.isCovariantByDeclaration = true;
|
||||
}
|
||||
if ((covariance & GenericCovariantImpl) != 0) {
|
||||
parameter.isGenericCovariantImpl = true;
|
||||
parameter.isCovariantByClass = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// Applies the [covariance] mask to parameter.
|
||||
static void covarianceToField(int covariance, Field field) {
|
||||
if ((covariance & Covariant) != 0) {
|
||||
field.isCovariant = true;
|
||||
field.isCovariantByDeclaration = true;
|
||||
}
|
||||
if ((covariance & GenericCovariantImpl) != 0) {
|
||||
field.isGenericCovariantImpl = true;
|
||||
field.isCovariantByClass = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,7 +133,7 @@ class Covariance {
|
||||
List<bool>? typeParameters;
|
||||
if (function.typeParameters.isNotEmpty) {
|
||||
for (int index = 0; index < function.typeParameters.length; index++) {
|
||||
if (function.typeParameters[index].isGenericCovariantImpl) {
|
||||
if (function.typeParameters[index].isCovariantByClass) {
|
||||
typeParameters ??=
|
||||
new List<bool>.filled(function.typeParameters.length, false);
|
||||
typeParameters[index] = true;
|
||||
@@ -289,7 +289,7 @@ class Covariance {
|
||||
for (int index = 0; index < typeParameters.length; index++) {
|
||||
if (index < function.typeParameters.length) {
|
||||
if (typeParameters[index]) {
|
||||
function.typeParameters[index].isGenericCovariantImpl = true;
|
||||
function.typeParameters[index].isCovariantByClass = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,7 +353,7 @@ class SourceClassBuilder extends ClassBuilderImpl
|
||||
}
|
||||
if (fieldBuilder.isClassInstanceMember &&
|
||||
fieldBuilder.isAssignable &&
|
||||
!fieldBuilder.isCovariant) {
|
||||
!fieldBuilder.isCovariantByDeclaration) {
|
||||
fieldVariance = Variance.combine(Variance.contravariant, fieldVariance);
|
||||
reportVariancePositionIfInvalid(fieldVariance, typeParameter,
|
||||
fieldBuilder.fileUri, fieldBuilder.charOffset);
|
||||
@@ -385,7 +385,7 @@ class SourceClassBuilder extends ClassBuilderImpl
|
||||
// ignore: unnecessary_null_comparison
|
||||
if (positionalParameters != null) {
|
||||
for (VariableDeclaration formal in positionalParameters) {
|
||||
if (!formal.isCovariant) {
|
||||
if (!formal.isCovariantByDeclaration) {
|
||||
for (TypeParameter typeParameter in typeParameters) {
|
||||
int formalVariance = Variance.combine(Variance.contravariant,
|
||||
computeVariance(typeParameter, formal.type));
|
||||
@@ -1285,7 +1285,7 @@ class SourceClassBuilder extends ClassBuilderImpl
|
||||
for (int i = 0; i < declaredFunction.typeParameters.length; ++i) {
|
||||
TypeParameter declaredParameter = declaredFunction.typeParameters[i];
|
||||
TypeParameter interfaceParameter = interfaceFunction!.typeParameters[i];
|
||||
if (!interfaceParameter.isGenericCovariantImpl) {
|
||||
if (!interfaceParameter.isCovariantByClass) {
|
||||
DartType declaredBound = declaredParameter.bound;
|
||||
DartType interfaceBound = interfaceParameter.bound;
|
||||
if (interfaceSubstitution != null) {
|
||||
@@ -1359,7 +1359,7 @@ class SourceClassBuilder extends ClassBuilderImpl
|
||||
Member interfaceMemberOrigin,
|
||||
DartType declaredType,
|
||||
DartType interfaceType,
|
||||
bool isCovariant,
|
||||
bool isCovariantByDeclaration,
|
||||
VariableDeclaration? declaredParameter,
|
||||
bool isInterfaceCheck,
|
||||
bool declaredNeedsLegacyErasure,
|
||||
@@ -1386,7 +1386,7 @@ class SourceClassBuilder extends ClassBuilderImpl
|
||||
if (types.isSubtypeOf(
|
||||
subtype, supertype, SubtypeCheckMode.withNullabilities)) {
|
||||
// No problem--the proper subtyping relation is satisfied.
|
||||
} else if (isCovariant &&
|
||||
} else if (isCovariantByDeclaration &&
|
||||
types.isSubtypeOf(
|
||||
supertype, subtype, SubtypeCheckMode.withNullabilities)) {
|
||||
// No problem--the overriding parameter is marked "covariant" and has
|
||||
@@ -1398,7 +1398,7 @@ class SourceClassBuilder extends ClassBuilderImpl
|
||||
// Report an error.
|
||||
bool isErrorInNnbdOptedOutMode = !types.isSubtypeOf(
|
||||
subtype, supertype, SubtypeCheckMode.ignoringNullabilities) &&
|
||||
(!isCovariant ||
|
||||
(!isCovariantByDeclaration ||
|
||||
!types.isSubtypeOf(
|
||||
supertype, subtype, SubtypeCheckMode.ignoringNullabilities));
|
||||
if (isErrorInNnbdOptedOutMode || library.isNonNullableByDefault) {
|
||||
@@ -1493,8 +1493,8 @@ class SourceClassBuilder extends ClassBuilderImpl
|
||||
interfaceMemberOrigin,
|
||||
declaredFunction.returnType,
|
||||
interfaceFunction.returnType,
|
||||
false,
|
||||
null,
|
||||
/* isCovariantByDeclaration = */ false,
|
||||
/* declaredParameter = */ null,
|
||||
isInterfaceCheck,
|
||||
declaredNeedsLegacyErasure);
|
||||
if (declaredFunction.positionalParameters.length <
|
||||
@@ -1563,11 +1563,12 @@ class SourceClassBuilder extends ClassBuilderImpl
|
||||
interfaceMemberOrigin,
|
||||
declaredParameter.type,
|
||||
interfaceParameter.type,
|
||||
declaredParameter.isCovariant || interfaceParameter.isCovariant,
|
||||
declaredParameter.isCovariantByDeclaration ||
|
||||
interfaceParameter.isCovariantByDeclaration,
|
||||
declaredParameter,
|
||||
isInterfaceCheck,
|
||||
declaredNeedsLegacyErasure);
|
||||
if (declaredParameter.isCovariant) seenCovariant = true;
|
||||
if (declaredParameter.isCovariantByDeclaration) seenCovariant = true;
|
||||
}
|
||||
if (declaredFunction.namedParameters.isEmpty &&
|
||||
interfaceFunction.namedParameters.isEmpty) {
|
||||
@@ -1643,7 +1644,7 @@ class SourceClassBuilder extends ClassBuilderImpl
|
||||
interfaceMemberOrigin,
|
||||
declaredParameter.type,
|
||||
interfaceNamedParameters.current.type,
|
||||
declaredParameter.isCovariant,
|
||||
declaredParameter.isCovariantByDeclaration,
|
||||
declaredParameter,
|
||||
isInterfaceCheck,
|
||||
declaredNeedsLegacyErasure);
|
||||
@@ -1670,7 +1671,7 @@ class SourceClassBuilder extends ClassBuilderImpl
|
||||
interfaceMemberOrigin.fileOffset, noLength)
|
||||
]);
|
||||
}
|
||||
if (declaredParameter.isCovariant) seenCovariant = true;
|
||||
if (declaredParameter.isCovariantByDeclaration) seenCovariant = true;
|
||||
}
|
||||
return seenCovariant;
|
||||
}
|
||||
@@ -1709,7 +1710,7 @@ class SourceClassBuilder extends ClassBuilderImpl
|
||||
interfaceMemberOrigin,
|
||||
declaredType,
|
||||
interfaceType,
|
||||
/* isCovariant = */ false,
|
||||
/* isCovariantByDeclaration = */ false,
|
||||
/* declaredParameter = */ null,
|
||||
isInterfaceCheck,
|
||||
declaredNeedsLegacyErasure);
|
||||
@@ -1745,12 +1746,13 @@ class SourceClassBuilder extends ClassBuilderImpl
|
||||
DartType interfaceType = interfaceMember.setterType;
|
||||
VariableDeclaration? declaredParameter =
|
||||
declaredMember.function?.positionalParameters.elementAt(0);
|
||||
bool isCovariant = declaredParameter?.isCovariant ?? false;
|
||||
if (!isCovariant && declaredMember is Field) {
|
||||
isCovariant = declaredMember.isCovariant;
|
||||
bool isCovariantByDeclaration =
|
||||
declaredParameter?.isCovariantByDeclaration ?? false;
|
||||
if (!isCovariantByDeclaration && declaredMember is Field) {
|
||||
isCovariantByDeclaration = declaredMember.isCovariantByDeclaration;
|
||||
}
|
||||
if (!isCovariant && interfaceMember is Field) {
|
||||
isCovariant = interfaceMember.isCovariant;
|
||||
if (!isCovariantByDeclaration && interfaceMember is Field) {
|
||||
isCovariantByDeclaration = interfaceMember.isCovariantByDeclaration;
|
||||
}
|
||||
_checkTypes(
|
||||
types,
|
||||
@@ -1761,12 +1763,12 @@ class SourceClassBuilder extends ClassBuilderImpl
|
||||
interfaceMemberOrigin,
|
||||
declaredType,
|
||||
interfaceType,
|
||||
isCovariant,
|
||||
isCovariantByDeclaration,
|
||||
declaredParameter,
|
||||
isInterfaceCheck,
|
||||
declaredNeedsLegacyErasure,
|
||||
asIfDeclaredParameter: true);
|
||||
return isCovariant;
|
||||
return isCovariantByDeclaration;
|
||||
}
|
||||
|
||||
// When the overriding member is inherited, report the class containing
|
||||
|
||||
@@ -368,8 +368,8 @@ type Field extends Member {
|
||||
UriReference fileUri;
|
||||
FileOffset fileOffset;
|
||||
FileOffset fileEndOffset;
|
||||
UInt flags (isFinal, isConst, isStatic, isCovariant,
|
||||
isGenericCovariantImpl, isLate, isExtensionMember,
|
||||
UInt flags (isFinal, isConst, isStatic, isCovariantByDeclaration,
|
||||
isCovariantByClass, isLate, isExtensionMember,
|
||||
isNonNullableByDefault, isInternalImplementation);
|
||||
Name name;
|
||||
List<Expression> annotations;
|
||||
@@ -1377,8 +1377,8 @@ type VariableDeclarationPlain {
|
||||
|
||||
List<Expression> annotations;
|
||||
|
||||
Byte flags (isFinal, isConst, isFieldFormal, isCovariant,
|
||||
isGenericCovariantImpl, isLate, isRequired, isLowered);
|
||||
Byte flags (isFinal, isConst, isFieldFormal, isCovariantByDeclaration,
|
||||
isCovariantByClass, isLate, isRequired, isLowered);
|
||||
// For named parameters, this is the parameter name.
|
||||
// For other variables, the name is cosmetic, may be empty,
|
||||
// and is not necessarily unique.
|
||||
@@ -1501,7 +1501,7 @@ type TypedefType {
|
||||
|
||||
type TypeParameter {
|
||||
// Note: there is no tag on TypeParameter
|
||||
Byte flags (isGenericCovariantImpl);
|
||||
Byte flags (isCovariantByClass);
|
||||
List<Expression> annotations;
|
||||
Byte variance; // Index into the Variance enum above
|
||||
StringReference name; // Cosmetic, may be empty, not unique.
|
||||
|
||||
+26
-26
@@ -1865,7 +1865,7 @@ class Field extends Member {
|
||||
Field.mutable(Name name,
|
||||
{this.type: const DynamicType(),
|
||||
this.initializer,
|
||||
bool isCovariant: false,
|
||||
bool isCovariantByDeclaration: false,
|
||||
bool isFinal: false,
|
||||
bool isStatic: false,
|
||||
bool isLate: false,
|
||||
@@ -1879,7 +1879,7 @@ class Field extends Member {
|
||||
// ignore: unnecessary_null_comparison
|
||||
assert(type != null);
|
||||
initializer?.parent = this;
|
||||
this.isCovariant = isCovariant;
|
||||
this.isCovariantByDeclaration = isCovariantByDeclaration;
|
||||
this.isFinal = isFinal;
|
||||
this.isStatic = isStatic;
|
||||
this.isLate = isLate;
|
||||
@@ -1889,7 +1889,7 @@ class Field extends Member {
|
||||
Field.immutable(Name name,
|
||||
{this.type: const DynamicType(),
|
||||
this.initializer,
|
||||
bool isCovariant: false,
|
||||
bool isCovariantByDeclaration: false,
|
||||
bool isFinal: false,
|
||||
bool isConst: false,
|
||||
bool isStatic: false,
|
||||
@@ -1902,7 +1902,7 @@ class Field extends Member {
|
||||
// ignore: unnecessary_null_comparison
|
||||
assert(type != null);
|
||||
initializer?.parent = this;
|
||||
this.isCovariant = isCovariant;
|
||||
this.isCovariantByDeclaration = isCovariantByDeclaration;
|
||||
this.isFinal = isFinal;
|
||||
this.isConst = isConst;
|
||||
this.isStatic = isStatic;
|
||||
@@ -1922,14 +1922,14 @@ class Field extends Member {
|
||||
static const int FlagConst = 1 << 1;
|
||||
static const int FlagStatic = 1 << 2;
|
||||
static const int FlagCovariant = 1 << 3;
|
||||
static const int FlagGenericCovariantImpl = 1 << 4;
|
||||
static const int FlagCovariantByClass = 1 << 4;
|
||||
static const int FlagLate = 1 << 5;
|
||||
static const int FlagExtensionMember = 1 << 6;
|
||||
static const int FlagNonNullableByDefault = 1 << 7;
|
||||
static const int FlagInternalImplementation = 1 << 8;
|
||||
|
||||
/// Whether the field is declared with the `covariant` keyword.
|
||||
bool get isCovariant => flags & FlagCovariant != 0;
|
||||
bool get isCovariantByDeclaration => flags & FlagCovariant != 0;
|
||||
|
||||
bool get isFinal => flags & FlagFinal != 0;
|
||||
|
||||
@@ -1946,7 +1946,7 @@ class Field extends Member {
|
||||
///
|
||||
/// When `true`, runtime checks may need to be performed; see
|
||||
/// [DispatchCategory] for details.
|
||||
bool get isGenericCovariantImpl => flags & FlagGenericCovariantImpl != 0;
|
||||
bool get isCovariantByClass => flags & FlagCovariantByClass != 0;
|
||||
|
||||
/// Whether the field is declared with the `late` keyword.
|
||||
bool get isLate => flags & FlagLate != 0;
|
||||
@@ -1958,7 +1958,7 @@ class Field extends Member {
|
||||
// lowering.
|
||||
bool get isInternalImplementation => flags & FlagInternalImplementation != 0;
|
||||
|
||||
void set isCovariant(bool value) {
|
||||
void set isCovariantByDeclaration(bool value) {
|
||||
flags = value ? (flags | FlagCovariant) : (flags & ~FlagCovariant);
|
||||
}
|
||||
|
||||
@@ -1979,10 +1979,10 @@ class Field extends Member {
|
||||
value ? (flags | FlagExtensionMember) : (flags & ~FlagExtensionMember);
|
||||
}
|
||||
|
||||
void set isGenericCovariantImpl(bool value) {
|
||||
void set isCovariantByClass(bool value) {
|
||||
flags = value
|
||||
? (flags | FlagGenericCovariantImpl)
|
||||
: (flags & ~FlagGenericCovariantImpl);
|
||||
? (flags | FlagCovariantByClass)
|
||||
: (flags & ~FlagCovariantByClass);
|
||||
}
|
||||
|
||||
void set isLate(bool value) {
|
||||
@@ -2396,8 +2396,8 @@ enum ProcedureStubKind {
|
||||
/// The stub target is `null`.
|
||||
Regular,
|
||||
|
||||
/// An abstract procedure inserted to add `isCovariant` and
|
||||
/// `isGenericCovariantImpl` to parameters for a set of overridden members.
|
||||
/// An abstract procedure inserted to add `isCovariantByDeclaration` and
|
||||
/// `isCovariantByClass` to parameters for a set of overridden members.
|
||||
///
|
||||
/// The stub is inserted when not all of the overridden members agree on
|
||||
/// the covariance flags. For instance:
|
||||
@@ -2422,8 +2422,8 @@ enum ProcedureStubKind {
|
||||
/// The stub target is one of the overridden members.
|
||||
AbstractForwardingStub,
|
||||
|
||||
/// A concrete procedure inserted to add `isCovariant` and
|
||||
/// `isGenericCovariantImpl` checks to parameters before calling the
|
||||
/// A concrete procedure inserted to add `isCovariantByDeclaration` and
|
||||
/// `isCovariantByClass` checks to parameters before calling the
|
||||
/// overridden member in the superclass.
|
||||
///
|
||||
/// The stub is inserted when not all of the overridden members agree on
|
||||
@@ -9927,7 +9927,7 @@ class VariableDeclaration extends Statement implements Annotatable {
|
||||
bool isFinal: false,
|
||||
bool isConst: false,
|
||||
bool isFieldFormal: false,
|
||||
bool isCovariant: false,
|
||||
bool isCovariantByDeclaration: false,
|
||||
bool isLate: false,
|
||||
bool isRequired: false,
|
||||
bool isLowered: false}) {
|
||||
@@ -9940,7 +9940,7 @@ class VariableDeclaration extends Statement implements Annotatable {
|
||||
this.isFinal = isFinal;
|
||||
this.isConst = isConst;
|
||||
this.isFieldFormal = isFieldFormal;
|
||||
this.isCovariant = isCovariant;
|
||||
this.isCovariantByDeclaration = isCovariantByDeclaration;
|
||||
this.isLate = isLate;
|
||||
this.isRequired = isRequired;
|
||||
this.isLowered = isLowered;
|
||||
@@ -9981,7 +9981,7 @@ class VariableDeclaration extends Statement implements Annotatable {
|
||||
|
||||
/// Whether the parameter is declared with the `covariant` keyword.
|
||||
// TODO(johnniwinther): Rename to isCovariantByDeclaration
|
||||
bool get isCovariant => flags & FlagCovariant != 0;
|
||||
bool get isCovariantByDeclaration => flags & FlagCovariant != 0;
|
||||
|
||||
/// Whether the variable is declared as a field formal parameter of
|
||||
/// a constructor.
|
||||
@@ -9995,7 +9995,7 @@ class VariableDeclaration extends Statement implements Annotatable {
|
||||
/// When `true`, runtime checks may need to be performed; see
|
||||
/// [DispatchCategory] for details.
|
||||
// TODO(johnniwinther): Rename to isCovariantByClass
|
||||
bool get isGenericCovariantImpl => flags & FlagGenericCovariantImpl != 0;
|
||||
bool get isCovariantByClass => flags & FlagGenericCovariantImpl != 0;
|
||||
|
||||
/// Whether the variable is declared with the `late` keyword.
|
||||
///
|
||||
@@ -10040,7 +10040,7 @@ class VariableDeclaration extends Statement implements Annotatable {
|
||||
flags = value ? (flags | FlagConst) : (flags & ~FlagConst);
|
||||
}
|
||||
|
||||
void set isCovariant(bool value) {
|
||||
void set isCovariantByDeclaration(bool value) {
|
||||
flags = value ? (flags | FlagCovariant) : (flags & ~FlagCovariant);
|
||||
}
|
||||
|
||||
@@ -10049,7 +10049,7 @@ class VariableDeclaration extends Statement implements Annotatable {
|
||||
flags = value ? (flags | FlagFieldFormal) : (flags & ~FlagFieldFormal);
|
||||
}
|
||||
|
||||
void set isGenericCovariantImpl(bool value) {
|
||||
void set isCovariantByClass(bool value) {
|
||||
flags = value
|
||||
? (flags | FlagGenericCovariantImpl)
|
||||
: (flags & ~FlagGenericCovariantImpl);
|
||||
@@ -12032,7 +12032,7 @@ class TypeParameter extends TreeNode implements Annotatable {
|
||||
defaultType = defaultType ?? unsetDefaultTypeSentinel;
|
||||
|
||||
// Must match serialized bit positions.
|
||||
static const int FlagGenericCovariantImpl = 1 << 0;
|
||||
static const int FlagCovariantByClass = 1 << 0;
|
||||
|
||||
/// If this [TypeParameter] is a type parameter of a generic method, indicates
|
||||
/// whether the method implementation needs to contain a runtime type check to
|
||||
@@ -12040,12 +12040,12 @@ class TypeParameter extends TreeNode implements Annotatable {
|
||||
///
|
||||
/// When `true`, runtime checks may need to be performed; see
|
||||
/// [DispatchCategory] for details.
|
||||
bool get isGenericCovariantImpl => flags & FlagGenericCovariantImpl != 0;
|
||||
bool get isCovariantByClass => flags & FlagCovariantByClass != 0;
|
||||
|
||||
void set isGenericCovariantImpl(bool value) {
|
||||
void set isCovariantByClass(bool value) {
|
||||
flags = value
|
||||
? (flags | FlagGenericCovariantImpl)
|
||||
: (flags & ~FlagGenericCovariantImpl);
|
||||
? (flags | FlagCovariantByClass)
|
||||
: (flags & ~FlagCovariantByClass);
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@@ -75,11 +75,13 @@ ${superMember} is a ${_memberKind(superMember)}
|
||||
if (isSetter) {
|
||||
final DartType ownType = setterType(host, ownMember);
|
||||
final DartType superType = setterType(host, superMember);
|
||||
final bool isCovariant = ownMember is Field
|
||||
? ownMember.isCovariant
|
||||
: ownMember.function!.positionalParameters[0].isCovariant;
|
||||
if (!_isValidParameterOverride(isCovariant, ownType, superType)) {
|
||||
if (isCovariant) {
|
||||
final bool isCovariantByDeclaration = ownMember is Field
|
||||
? ownMember.isCovariantByDeclaration
|
||||
: ownMember
|
||||
.function!.positionalParameters[0].isCovariantByDeclaration;
|
||||
if (!_isValidParameterOverride(
|
||||
isCovariantByDeclaration, ownType, superType)) {
|
||||
if (isCovariantByDeclaration) {
|
||||
return failures.reportInvalidOverride(ownMember, superMember, '''
|
||||
${ownType} is neither a subtype nor supertype of ${superType}
|
||||
''');
|
||||
@@ -198,7 +200,7 @@ ${ownType} is not a subtype of ${superType}
|
||||
final VariableDeclaration superParameter =
|
||||
superFunction.positionalParameters[i];
|
||||
if (!_isValidParameterOverride(
|
||||
ownParameter.isCovariant,
|
||||
ownParameter.isCovariantByDeclaration,
|
||||
ownSubstitution.substituteType(ownParameter.type),
|
||||
superSubstitution.substituteType(superParameter.type))) {
|
||||
return '''
|
||||
@@ -227,7 +229,7 @@ super method declares ${superParameter.type}
|
||||
}
|
||||
|
||||
if (!_isValidParameterOverride(
|
||||
ownParameter.isCovariant,
|
||||
ownParameter.isCovariantByDeclaration,
|
||||
ownSubstitution.substituteType(ownParameter.type),
|
||||
superSubstitution.substituteType(superParameter.type))) {
|
||||
return '''
|
||||
@@ -244,11 +246,11 @@ super method declares ${superParameter.type}
|
||||
/// Checks whether parameter with [ownParameterType] type is a valid override
|
||||
/// for parameter with [superParameterType] type taking into account its
|
||||
/// covariance and applying type parameter [substitution] if necessary.
|
||||
bool _isValidParameterOverride(bool isCovariant, DartType ownParameterType,
|
||||
DartType superParameterType) {
|
||||
bool _isValidParameterOverride(bool isCovariantByDeclaration,
|
||||
DartType ownParameterType, DartType superParameterType) {
|
||||
if (_isSubtypeOf(superParameterType, ownParameterType)) {
|
||||
return true;
|
||||
} else if (isCovariant &&
|
||||
} else if (isCovariantByDeclaration &&
|
||||
_isSubtypeOf(ownParameterType, superParameterType)) {
|
||||
return true;
|
||||
} else {
|
||||
|
||||
@@ -1123,8 +1123,8 @@ class Printer extends Visitor<void> with VisitorVoidMixin {
|
||||
writeIndentation();
|
||||
writeModifier(node.isLate, 'late');
|
||||
writeModifier(node.isStatic, 'static');
|
||||
writeModifier(node.isCovariant, 'covariant');
|
||||
writeModifier(node.isGenericCovariantImpl, 'generic-covariant-impl');
|
||||
writeModifier(node.isCovariantByDeclaration, 'covariant');
|
||||
writeModifier(node.isCovariantByClass, 'generic-covariant-impl');
|
||||
writeModifier(node.isFinal, 'final');
|
||||
writeModifier(node.isConst, 'const');
|
||||
// Only show implicit getter/setter modifiers in cases where they are
|
||||
@@ -2404,8 +2404,8 @@ class Printer extends Visitor<void> with VisitorVoidMixin {
|
||||
writeModifier(node.isLowered, 'lowered');
|
||||
writeModifier(node.isLate, 'late');
|
||||
writeModifier(node.isRequired, 'required');
|
||||
writeModifier(node.isCovariant, 'covariant');
|
||||
writeModifier(node.isGenericCovariantImpl, 'generic-covariant-impl');
|
||||
writeModifier(node.isCovariantByDeclaration, 'covariant');
|
||||
writeModifier(node.isCovariantByClass, 'generic-covariant-impl');
|
||||
writeModifier(node.isFinal, 'final');
|
||||
writeModifier(node.isConst, 'const');
|
||||
// ignore: unnecessary_null_comparison
|
||||
@@ -2623,7 +2623,7 @@ class Printer extends Visitor<void> with VisitorVoidMixin {
|
||||
|
||||
@override
|
||||
void visitTypeParameter(TypeParameter node) {
|
||||
writeModifier(node.isGenericCovariantImpl, 'generic-covariant-impl');
|
||||
writeModifier(node.isCovariantByClass, 'generic-covariant-impl');
|
||||
writeAnnotationList(node.annotations, separateLines: false);
|
||||
if (node.variance != Variance.covariant) {
|
||||
writeWord(const <String>[
|
||||
|
||||
@@ -1980,7 +1980,7 @@ const Map<int, String> fieldFlagToName = const {
|
||||
Field.FlagConst: "const",
|
||||
Field.FlagStatic: "static",
|
||||
Field.FlagCovariant: "covariant",
|
||||
Field.FlagGenericCovariantImpl: "generic-covariant-impl",
|
||||
Field.FlagCovariantByClass: "generic-covariant-impl",
|
||||
Field.FlagLate: "late",
|
||||
Field.FlagExtensionMember: "extension-member",
|
||||
Field.FlagNonNullableByDefault: "non-nullable-by-default",
|
||||
|
||||
@@ -139,8 +139,8 @@ class MixinFullResolution {
|
||||
setters.remove(field.name);
|
||||
VariableDeclaration parameter =
|
||||
setter.function.positionalParameters.first;
|
||||
clone.isCovariant = parameter.isCovariant;
|
||||
clone.isGenericCovariantImpl = parameter.isGenericCovariantImpl;
|
||||
clone.isCovariantByDeclaration = parameter.isCovariantByDeclaration;
|
||||
clone.isCovariantByClass = parameter.isCovariantByClass;
|
||||
}
|
||||
nonSetters.remove(field.name);
|
||||
class_.addField(clone);
|
||||
@@ -225,10 +225,10 @@ class MixinFullResolution {
|
||||
// TODO(kernel team): The named parameters are not sorted,
|
||||
// this might not be correct.
|
||||
for (int j = 0; j < src.namedParameters.length; ++j) {
|
||||
dst.namedParameters[j].isCovariant =
|
||||
src.namedParameters[j].isCovariant;
|
||||
dst.namedParameters[j].isGenericCovariantImpl =
|
||||
src.namedParameters[j].isGenericCovariantImpl;
|
||||
dst.namedParameters[j].isCovariantByDeclaration =
|
||||
src.namedParameters[j].isCovariantByDeclaration;
|
||||
dst.namedParameters[j].isCovariantByClass =
|
||||
src.namedParameters[j].isCovariantByClass;
|
||||
}
|
||||
|
||||
class_.procedures[originalIndex] = clone;
|
||||
|
||||
@@ -110,7 +110,7 @@ class AnnotateWithStaticTypes extends RecursiveVisitor {
|
||||
/// Return [true] if the given list of [VariableDeclaration] contains
|
||||
/// any annotated with generic-covariant-impl.
|
||||
static bool containsGenericCovariantImpl(List<VariableDeclaration> decls) =>
|
||||
decls.any((p) => p.isGenericCovariantImpl);
|
||||
decls.any((p) => p.isCovariantByClass);
|
||||
|
||||
/// Returns [true] if the given [member] has any parameters annotated with
|
||||
/// generic-covariant-impl attribute.
|
||||
@@ -120,7 +120,7 @@ class AnnotateWithStaticTypes extends RecursiveVisitor {
|
||||
member.function.positionalParameters) ||
|
||||
containsGenericCovariantImpl(member.function.namedParameters);
|
||||
} else if (member is Field) {
|
||||
return member.isGenericCovariantImpl;
|
||||
return member.isCovariantByClass;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
@@ -195,12 +195,12 @@ class _DirectInvocation extends _Invocation {
|
||||
final function = selector.member.function;
|
||||
if (function != null) {
|
||||
typeChecksNeeded =
|
||||
function.typeParameters.any((t) => t.isGenericCovariantImpl);
|
||||
function.typeParameters.any((t) => t.isCovariantByClass);
|
||||
} else {
|
||||
Field field = selector.member as Field;
|
||||
if (selector.callKind == CallKind.PropertySet) {
|
||||
// TODO(dartbug.com/40615): Use TFA results to improve this criterion.
|
||||
typeChecksNeeded = field.isGenericCovariantImpl;
|
||||
typeChecksNeeded = field.isCovariantByClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1499,7 +1499,7 @@ class TypeFlowAnalysis implements EntryPointsListener, CallHandler {
|
||||
_FieldValue? fieldValue = _fieldValues[field];
|
||||
if (fieldValue == null) {
|
||||
Summary? typeGuardSummary = null;
|
||||
if (field.isGenericCovariantImpl) {
|
||||
if (field.isCovariantByClass) {
|
||||
typeGuardSummary = summaryCollector.createSummary(field,
|
||||
fieldSummaryType: FieldSummaryType.kFieldGuard);
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ class _ParameterInfo {
|
||||
// Covariant parameters have implicit type checks, which count as reads.
|
||||
// When run in weak mode with null assertions enabled, parameters with
|
||||
// non-nullable types have implicit null checks, which count as reads.
|
||||
if ((param.isCovariant || param.isGenericCovariantImpl) ||
|
||||
if ((param.isCovariantByDeclaration || param.isCovariantByClass) ||
|
||||
(!shaker.typeFlowAnalysis.target.flags.enableNullSafety &&
|
||||
param.type.nullability == Nullability.nonNullable &&
|
||||
(type == null || type is NullableType))) {
|
||||
|
||||
@@ -546,7 +546,7 @@ class TypeCheck extends Statement {
|
||||
|
||||
TypeCheck(this.arg, this.type, this.node, this.staticType, this.kind)
|
||||
: isTestedOnlyOnCheckedEntryPoint =
|
||||
node is VariableDeclaration && !node.isCovariant;
|
||||
node is VariableDeclaration && !node.isCovariantByDeclaration;
|
||||
|
||||
@override
|
||||
void accept(StatementVisitor visitor) => visitor.visitTypeCheck(this);
|
||||
|
||||
@@ -801,7 +801,7 @@ class SummaryCollector extends RecursiveResultVisitor<TypeExpr?> {
|
||||
}
|
||||
|
||||
bool _useTypeCheckForParameter(VariableDeclaration decl) {
|
||||
return decl.isCovariant || decl.isGenericCovariantImpl;
|
||||
return decl.isCovariantByDeclaration || decl.isCovariantByClass;
|
||||
}
|
||||
|
||||
Args<Type> rawArguments(Selector selector) {
|
||||
|
||||
@@ -880,8 +880,8 @@ class FieldMorpher {
|
||||
if (isSetter) {
|
||||
final isAbstract = !shaker.isFieldSetterReachable(field);
|
||||
final parameter = new VariableDeclaration('value', type: field.type)
|
||||
..isCovariant = field.isCovariant
|
||||
..isGenericCovariantImpl = field.isGenericCovariantImpl
|
||||
..isCovariantByDeclaration = field.isCovariantByDeclaration
|
||||
..isCovariantByClass = field.isCovariantByClass
|
||||
..fileOffset = field.fileOffset;
|
||||
accessor = new Procedure(
|
||||
field.name,
|
||||
|
||||
Reference in New Issue
Block a user