Skip to content

Commit

Permalink
Version 3.7.0-319.0.dev
Browse files Browse the repository at this point in the history
Merge 9a47293 into dev
  • Loading branch information
Dart CI committed Jan 11, 2025
2 parents 357a919 + 9a47293 commit 082be8f
Show file tree
Hide file tree
Showing 18 changed files with 428 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -967,7 +967,7 @@ mixin TypeAnalyzerOperationsMixin<
// constraints (i.e. `X <: B` in this example), then they are added to
// the set of constraints just before choosing the final type.

TypeStructure typeParameterToInferBound = typeParameterToInfer.bound!;
TypeStructure typeParameterToInferBound = typeParameterToInfer.boundShared!;

// TODO(cstefantsova): Pass [dataForTesting] when
// [InferenceDataForTesting] is merged with [TypeInferenceResultForTesting].
Expand Down Expand Up @@ -1231,16 +1231,16 @@ abstract class TypeConstraintGenerator<
// with respect to `L` under constraints `C0 + ... + Cm`
// If for `i` in `0...m`, `Mi` is a subtype match for `Ni` with respect
// to `L` under constraints `Ci`.
if (p.positionalTypes.length != q.positionalTypes.length ||
p.sortedNamedTypes.length != q.sortedNamedTypes.length) {
if (p.positionalTypesShared.length != q.positionalTypesShared.length ||
p.sortedNamedTypesShared.length != q.sortedNamedTypesShared.length) {
return false;
}

final TypeConstraintGeneratorState state = currentState;

for (int i = 0; i < p.positionalTypes.length; ++i) {
for (int i = 0; i < p.positionalTypesShared.length; ++i) {
if (!performSubtypeConstraintGenerationInternal(
p.positionalTypes[i], q.positionalTypes[i],
p.positionalTypesShared[i], q.positionalTypesShared[i],
leftSchema: leftSchema, astNodeForTesting: astNodeForTesting)) {
restoreState(state);
return false;
Expand All @@ -1251,12 +1251,14 @@ abstract class TypeConstraintGenerator<
// parameters, and the named parameters are sorted, it's sufficient to
// check that the named parameters at the same index have the same name
// and matching types.
for (int i = 0; i < p.sortedNamedTypes.length; ++i) {
if (p.sortedNamedTypes[i].nameShared !=
q.sortedNamedTypes[i].nameShared ||
for (int i = 0; i < p.sortedNamedTypesShared.length; ++i) {
if (p.sortedNamedTypesShared[i].nameShared !=
q.sortedNamedTypesShared[i].nameShared ||
!performSubtypeConstraintGenerationInternal(
p.sortedNamedTypes[i].type, q.sortedNamedTypes[i].type,
leftSchema: leftSchema, astNodeForTesting: astNodeForTesting)) {
p.sortedNamedTypesShared[i].typeShared,
q.sortedNamedTypesShared[i].typeShared,
leftSchema: leftSchema,
astNodeForTesting: astNodeForTesting)) {
restoreState(state);
return false;
}
Expand Down Expand Up @@ -1506,11 +1508,11 @@ abstract class TypeConstraintGenerator<
when qNullability == NullabilitySuffix.none &&
typeParametersToConstrain.contains(qParameter) &&
(!inferenceUsingBoundsIsEnabled ||
(qParameter.bound == null ||
(qParameter.boundShared == null ||
typeAnalyzerOperations.isSubtypeOfInternal(
p,
typeAnalyzerOperations.greatestClosureOfTypeInternal(
qParameter.bound!,
qParameter.boundShared!,
[...typeParametersToConstrain]))))) {
addLowerConstraintForParameter(qParameter, p,
astNodeForTesting: astNodeForTesting);
Expand Down Expand Up @@ -1704,16 +1706,16 @@ abstract class TypeConstraintGenerator<
for (int i = 0; isMatch && i < p.typeParametersShared.length; ++i) {
isMatch = isMatch &&
performSubtypeConstraintGenerationInternal(
p.typeParametersShared[i].bound ??
p.typeParametersShared[i].boundShared ??
typeAnalyzerOperations.objectQuestionType.unwrapTypeView(),
q.typeParametersShared[i].bound ??
q.typeParametersShared[i].boundShared ??
typeAnalyzerOperations.objectQuestionType.unwrapTypeView(),
leftSchema: leftSchema,
astNodeForTesting: astNodeForTesting) &&
performSubtypeConstraintGenerationInternal(
q.typeParametersShared[i].bound ??
q.typeParametersShared[i].boundShared ??
typeAnalyzerOperations.objectQuestionType.unwrapTypeView(),
p.typeParametersShared[i].bound ??
p.typeParametersShared[i].boundShared ??
typeAnalyzerOperations.objectQuestionType.unwrapTypeView(),
leftSchema: !leftSchema,
astNodeForTesting: astNodeForTesting);
Expand Down Expand Up @@ -1767,27 +1769,29 @@ abstract class TypeConstraintGenerator<
q.sortedNamedParametersShared.isEmpty &&
p.requiredPositionalParameterCount <=
q.requiredPositionalParameterCount &&
p.positionalParameterTypes.length >=
q.positionalParameterTypes.length) {
p.positionalParameterTypesShared.length >=
q.positionalParameterTypesShared.length) {
final TypeConstraintGeneratorState state = currentState;

if (!performSubtypeConstraintGenerationInternal(
p.returnType, q.returnType,
p.returnTypeShared, q.returnTypeShared,
leftSchema: leftSchema, astNodeForTesting: astNodeForTesting)) {
return false;
}
for (int i = 0; i < q.positionalParameterTypes.length; ++i) {
for (int i = 0; i < q.positionalParameterTypesShared.length; ++i) {
if (!performSubtypeConstraintGenerationInternal(
q.positionalParameterTypes[i], p.positionalParameterTypes[i],
leftSchema: !leftSchema, astNodeForTesting: astNodeForTesting)) {
q.positionalParameterTypesShared[i],
p.positionalParameterTypesShared[i],
leftSchema: !leftSchema,
astNodeForTesting: astNodeForTesting)) {
restoreState(state);
return false;
}
}
return true;
} else if (p.positionalParameterTypes.length ==
} else if (p.positionalParameterTypesShared.length ==
p.requiredPositionalParameterCount &&
q.positionalParameterTypes.length ==
q.positionalParameterTypesShared.length ==
q.requiredPositionalParameterCount &&
p.requiredPositionalParameterCount ==
q.requiredPositionalParameterCount &&
Expand All @@ -1800,14 +1804,16 @@ abstract class TypeConstraintGenerator<
final TypeConstraintGeneratorState state = currentState;

if (!performSubtypeConstraintGenerationInternal(
p.returnType, q.returnType,
p.returnTypeShared, q.returnTypeShared,
leftSchema: leftSchema, astNodeForTesting: astNodeForTesting)) {
return false;
}
for (int i = 0; i < p.positionalParameterTypes.length; ++i) {
for (int i = 0; i < p.positionalParameterTypesShared.length; ++i) {
if (!performSubtypeConstraintGenerationInternal(
q.positionalParameterTypes[i], p.positionalParameterTypes[i],
leftSchema: !leftSchema, astNodeForTesting: astNodeForTesting)) {
q.positionalParameterTypesShared[i],
p.positionalParameterTypesShared[i],
leftSchema: !leftSchema,
astNodeForTesting: astNodeForTesting)) {
restoreState(state);
return false;
}
Expand Down Expand Up @@ -1859,8 +1865,8 @@ abstract class TypeConstraintGenerator<
} else {
// The next parameter in p and q matches, so match their types.
if (!performSubtypeConstraintGenerationInternal(
q.sortedNamedParametersShared[j].type,
p.sortedNamedParametersShared[i].type,
q.sortedNamedParametersShared[j].typeShared,
p.sortedNamedParametersShared[i].typeShared,
leftSchema: !leftSchema,
astNodeForTesting: astNodeForTesting)) {
restoreState(state);
Expand Down
28 changes: 14 additions & 14 deletions pkg/_fe_analyzer_shared/lib/src/types/shared_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ abstract interface class SharedFunctionTypeStructure<
TypeStructure>> implements SharedTypeStructure<TypeStructure> {
/// All the positional parameter types, starting with the required ones, and
/// followed by the optional ones.
List<TypeStructure> get positionalParameterTypes;
List<TypeStructure> get positionalParameterTypesShared;

/// The number of elements of [positionalParameterTypes] that are required
/// parameters.
/// The number of elements of [positionalParameterTypesShared] that are
/// required parameters.
int get requiredPositionalParameterCount;

/// The return type.
TypeStructure get returnType;
TypeStructure get returnTypeShared;

/// All the named parameters, sorted by name.
List<FunctionParameterStructure> get sortedNamedParametersShared;
Expand Down Expand Up @@ -55,15 +55,15 @@ abstract interface class SharedNamedFunctionParameterStructure<
String get nameShared;

/// The type of the parameter.
TypeStructure get type;
TypeStructure get typeShared;
}

/// Common interface for data structures used by the implementations to
/// represent a name/type pair.
abstract interface class SharedNamedTypeStructure<
TypeStructure extends SharedTypeStructure<TypeStructure>> {
String get nameShared;
TypeStructure get type;
TypeStructure get typeShared;
}

/// Common interface for data structures used by implementations to represent
Expand All @@ -77,18 +77,18 @@ abstract interface class SharedNullTypeStructure<
abstract interface class SharedRecordTypeStructure<
TypeStructure extends SharedTypeStructure<TypeStructure>>
implements SharedTypeStructure<TypeStructure> {
List<TypeStructure> get positionalTypes;
List<TypeStructure> get positionalTypesShared;

/// All the named fields, sorted by name.
List<SharedNamedTypeStructure<TypeStructure>> get sortedNamedTypes;
List<SharedNamedTypeStructure<TypeStructure>> get sortedNamedTypesShared;
}

/// Common interface for data structures used by the implementations to
/// represent a generic type parameter.
abstract interface class SharedTypeParameterStructure<
TypeStructure extends SharedTypeStructure<TypeStructure>> {
/// The bound of the type parameter.
TypeStructure? get bound;
TypeStructure? get boundShared;

/// The name of the type parameter, for display to the user.
String get displayName;
Expand Down Expand Up @@ -159,20 +159,20 @@ extension type SharedNamedTypeView<
String get name => _namedTypeStructure.nameShared;

SharedTypeView<TypeStructure> get type =>
new SharedTypeView(_namedTypeStructure.type);
new SharedTypeView(_namedTypeStructure.typeShared);
}

extension type SharedRecordTypeSchemaView<
TypeStructure extends SharedTypeStructure<TypeStructure>>(
SharedRecordTypeStructure<TypeStructure> _typeStructure)
implements SharedTypeSchemaView<TypeStructure> {
List<SharedNamedTypeSchemaView<TypeStructure>> get namedTypes {
return _typeStructure.sortedNamedTypes
return _typeStructure.sortedNamedTypesShared
as List<SharedNamedTypeSchemaView<TypeStructure>>;
}

List<SharedTypeSchemaView<TypeStructure>> get positionalTypes {
return _typeStructure.positionalTypes
return _typeStructure.positionalTypesShared
as List<SharedTypeSchemaView<TypeStructure>>;
}
}
Expand All @@ -182,12 +182,12 @@ extension type SharedRecordTypeView<
SharedRecordTypeStructure<TypeStructure> _typeStructure)
implements SharedTypeView<TypeStructure> {
List<SharedNamedTypeView<TypeStructure>> get namedTypes {
return _typeStructure.sortedNamedTypes
return _typeStructure.sortedNamedTypesShared
as List<SharedNamedTypeView<TypeStructure>>;
}

List<SharedTypeView<TypeStructure>> get positionalTypes {
return _typeStructure.positionalTypes
return _typeStructure.positionalTypesShared
as List<SharedTypeView<TypeStructure>>;
}
}
Expand Down
27 changes: 21 additions & 6 deletions pkg/_fe_analyzer_shared/test/mini_types.dart
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class FunctionType extends Type
implements
SharedFunctionTypeStructure<Type, TypeParameter,
NamedFunctionParameter> {
@override
final Type returnType;

@override
Expand Down Expand Up @@ -147,9 +146,14 @@ class FunctionType extends Type
}
}

@override
List<Type> get positionalParameterTypes => positionalParameters;

@override
List<Type> get positionalParameterTypesShared => positionalParameterTypes;

@override
Type get returnTypeShared => returnType;

@override
List<NamedFunctionParameter> get sortedNamedParametersShared =>
namedParameters;
Expand Down Expand Up @@ -412,7 +416,6 @@ class NamedFunctionParameter
_Substitutable<NamedFunctionParameter> {
final String name;

@override
final Type type;

@override
Expand All @@ -427,6 +430,9 @@ class NamedFunctionParameter
@override
String get nameShared => name;

@override
Type get typeShared => type;

@override
bool operator ==(Object other) =>
other is NamedFunctionParameter &&
Expand All @@ -450,7 +456,6 @@ class NamedType
implements SharedNamedTypeStructure<Type>, _Substitutable<NamedType> {
final String name;

@override
final Type type;

NamedType({required this.name, required this.type});
Expand All @@ -461,6 +466,9 @@ class NamedType
@override
String get nameShared => name;

@override
Type get typeShared => type;

@override
bool operator ==(Object other) =>
other is NamedType && name == other.name && type == other.type;
Expand Down Expand Up @@ -600,7 +608,6 @@ class PrimaryType extends Type {
}

class RecordType extends Type implements SharedRecordTypeStructure<Type> {
@override
final List<Type> positionalTypes;

final List<NamedType> namedTypes;
Expand All @@ -624,8 +631,14 @@ class RecordType extends Type implements SharedRecordTypeStructure<Type> {
nullabilitySuffix);

@override
List<Type> get positionalTypesShared => positionalTypes;

List<NamedType> get sortedNamedTypes => namedTypes;

@override
List<SharedNamedTypeStructure<Type>> get sortedNamedTypesShared =>
sortedNamedTypes;

@override
bool operator ==(Object other) =>
other is RecordType &&
Expand Down Expand Up @@ -888,9 +901,11 @@ class TypeParameter extends TypeNameInfo

TypeParameter._(super.name) : super(expectedRuntimeType: TypeParameterType);

@override
Type get bound => explicitBound ?? Type('Object?');

@override
Type? get boundShared => bound;

@override
String get displayName => name;

Expand Down
10 changes: 8 additions & 2 deletions pkg/analyzer/lib/src/dart/element/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4493,6 +4493,9 @@ class FormalParameterElementImpl extends PromotableElementImpl2
// TODO(augmentations): Implement the merge of formal parameters.
List<TypeParameterElement2> get typeParameters2 => const [];

@override
DartType get typeShared => type;

@override
Element? get _enclosingFunction => wrappedElement._enclosingElement3;

Expand Down Expand Up @@ -10851,7 +10854,7 @@ class TypeParameterElementImpl extends ElementImpl
// chain will have their `_element` set to the newly created element.
return TypeParameterElementImpl2(
firstFragment: firstFragment,
name3: firstFragment.name,
name3: firstFragment.name.nullIfEmpty,
bound: firstFragment.bound,
);
}
Expand Down Expand Up @@ -10971,7 +10974,7 @@ class TypeParameterElementImpl2 extends TypeDefiningElementImpl2
final TypeParameterElementImpl firstFragment;

@override
final String name3;
final String? name3;

@override
DartType? bound;
Expand All @@ -10991,6 +10994,9 @@ class TypeParameterElementImpl2 extends TypeDefiningElementImpl2
@override
TypeParameterElement2 get baseElement => this;

@override
DartType? get boundShared => bound;

bool get isLegacyCovariant => firstFragment.isLegacyCovariant;

@override
Expand Down
Loading

0 comments on commit 082be8f

Please sign in to comment.