diff --git a/pkg/front_end/lib/src/base/scope.dart b/pkg/front_end/lib/src/base/scope.dart index 80fb3e98dde1..79718eed1495 100644 --- a/pkg/front_end/lib/src/base/scope.dart +++ b/pkg/front_end/lib/src/base/scope.dart @@ -746,8 +746,8 @@ mixin ErroneousMemberBuilderMixin implements SourceMemberBuilder { @override // Coverage-ignore(suite): Not run. - void checkTypes( - SourceLibraryBuilder library, TypeEnvironment typeEnvironment) { + void checkTypes(SourceLibraryBuilder library, NameSpace nameSpace, + TypeEnvironment typeEnvironment) { assert(false, "Unexpected call to $runtimeType.checkVariance."); } diff --git a/pkg/front_end/lib/src/source/source_builder_mixins.dart b/pkg/front_end/lib/src/source/source_builder_mixins.dart index 921d49f9fcb4..cd25fde5189c 100644 --- a/pkg/front_end/lib/src/source/source_builder_mixins.dart +++ b/pkg/front_end/lib/src/source/source_builder_mixins.dart @@ -14,17 +14,13 @@ import '../builder/builder_mixins.dart'; import '../builder/declaration_builders.dart'; import '../builder/library_builder.dart'; import '../builder/member_builder.dart'; -import '../builder/procedure_builder.dart'; import '../builder/type_builder.dart'; import '../kernel/body_builder_context.dart'; import '../kernel/kernel_helper.dart'; import '../kernel/type_algorithms.dart'; -import 'source_constructor_builder.dart'; -import 'source_field_builder.dart'; import 'source_library_builder.dart'; import 'source_loader.dart'; import 'source_member_builder.dart'; -import 'source_procedure_builder.dart'; abstract class SourceDeclarationBuilder implements IDeclarationBuilder { void buildScopes(LibraryBuilder coreLibrary); @@ -155,30 +151,13 @@ mixin SourceDeclarationBuilderMixin void checkTypesInOutline(TypeEnvironment typeEnvironment) { forEach((String name, Builder builder) { - if (builder is SourceFieldBuilder) { - // Check fields. - libraryBuilder.checkTypesInField(builder, typeEnvironment); - } else if (builder is SourceProcedureBuilder) { - // Check procedures - libraryBuilder.checkTypesInFunctionBuilder(builder, typeEnvironment); - if (builder.isGetter) { - Builder? setterDeclaration = - nameSpace.lookupLocalMember(builder.name, setter: true); - if (setterDeclaration != null) { - libraryBuilder.checkGetterSetterTypes(builder, - setterDeclaration as ProcedureBuilder, typeEnvironment); - } - } - } else { - // Coverage-ignore-block(suite): Not run. - assert(false, "Unexpected member: $builder."); - } + (builder as SourceMemberBuilder) + .checkTypes(libraryBuilder, nameSpace, typeEnvironment); }); nameSpace.forEachConstructor((String name, MemberBuilder builder) { - if (builder is SourceConstructorBuilder) { - builder.checkTypes(libraryBuilder, typeEnvironment); - } + (builder as SourceMemberBuilder) + .checkTypes(libraryBuilder, nameSpace, typeEnvironment); }); } diff --git a/pkg/front_end/lib/src/source/source_class_builder.dart b/pkg/front_end/lib/src/source/source_class_builder.dart index f475e4288eec..e625fa609e44 100644 --- a/pkg/front_end/lib/src/source/source_class_builder.dart +++ b/pkg/front_end/lib/src/source/source_class_builder.dart @@ -1152,14 +1152,14 @@ class SourceClassBuilder extends ClassBuilderImpl while (memberIterator.moveNext()) { SourceMemberBuilder builder = memberIterator.current; builder.checkVariance(this, typeEnvironment); - builder.checkTypes(libraryBuilder, typeEnvironment); + builder.checkTypes(libraryBuilder, nameSpace, typeEnvironment); } Iterator constructorIterator = fullConstructorIterator(); while (constructorIterator.moveNext()) { SourceMemberBuilder builder = constructorIterator.current; - builder.checkTypes(libraryBuilder, typeEnvironment); + builder.checkTypes(libraryBuilder, nameSpace, typeEnvironment); } } diff --git a/pkg/front_end/lib/src/source/source_constructor_builder.dart b/pkg/front_end/lib/src/source/source_constructor_builder.dart index 7a0efd0b1589..3fcd75492b26 100644 --- a/pkg/front_end/lib/src/source/source_constructor_builder.dart +++ b/pkg/front_end/lib/src/source/source_constructor_builder.dart @@ -21,6 +21,7 @@ import '../base/messages.dart' messageSuperInitializerNotLast, noLength; import '../base/modifiers.dart'; +import '../base/name_space.dart'; import '../base/scope.dart'; import '../builder/builder.dart'; import '../builder/constructor_builder.dart'; @@ -362,8 +363,8 @@ abstract class AbstractSourceConstructorBuilder SourceClassBuilder sourceClassBuilder, TypeEnvironment typeEnvironment) {} @override - void checkTypes( - SourceLibraryBuilder library, TypeEnvironment typeEnvironment) { + void checkTypes(SourceLibraryBuilder library, NameSpace nameSpace, + TypeEnvironment typeEnvironment) { library.checkTypesInConstructorBuilder(this, formals, typeEnvironment); } @@ -986,13 +987,13 @@ class DeclaredSourceConstructorBuilder } @override - void checkTypes( - SourceLibraryBuilder library, TypeEnvironment typeEnvironment) { - super.checkTypes(library, typeEnvironment); + void checkTypes(SourceLibraryBuilder library, NameSpace nameSpace, + TypeEnvironment typeEnvironment) { + super.checkTypes(library, nameSpace, typeEnvironment); List? augmentations = _augmentations; if (augmentations != null) { for (DeclaredSourceConstructorBuilder augmentation in augmentations) { - augmentation.checkTypes(library, typeEnvironment); + augmentation.checkTypes(library, nameSpace, typeEnvironment); } } } @@ -1214,8 +1215,8 @@ class SyntheticSourceConstructorBuilder extends MemberBuilderImpl SourceClassBuilder sourceClassBuilder, TypeEnvironment typeEnvironment) {} @override - void checkTypes( - SourceLibraryBuilder library, TypeEnvironment typeEnvironment) {} + void checkTypes(SourceLibraryBuilder library, NameSpace nameSpace, + TypeEnvironment typeEnvironment) {} } class SourceExtensionTypeConstructorBuilder diff --git a/pkg/front_end/lib/src/source/source_factory_builder.dart b/pkg/front_end/lib/src/source/source_factory_builder.dart index 279803da56f0..3fc719abb4e5 100644 --- a/pkg/front_end/lib/src/source/source_factory_builder.dart +++ b/pkg/front_end/lib/src/source/source_factory_builder.dart @@ -16,6 +16,7 @@ import '../base/messages.dart' templateRedirectingFactoryIncompatibleTypeArgument, templateTypeArgumentMismatch; import '../base/modifiers.dart'; +import '../base/name_space.dart'; import '../base/problems.dart' show unexpected, unhandled; import '../base/scope.dart'; import '../builder/builder.dart'; @@ -318,13 +319,13 @@ class SourceFactoryBuilder extends SourceFunctionBuilderImpl { SourceClassBuilder sourceClassBuilder, TypeEnvironment typeEnvironment) {} @override - void checkTypes( - SourceLibraryBuilder library, TypeEnvironment typeEnvironment) { + void checkTypes(SourceLibraryBuilder library, NameSpace nameSpace, + TypeEnvironment typeEnvironment) { library.checkTypesInFunctionBuilder(this, typeEnvironment); List? augmentations = _augmentations; if (augmentations != null) { for (SourceFactoryBuilder augmentation in augmentations) { - augmentation.checkTypes(library, typeEnvironment); + augmentation.checkTypes(library, nameSpace, typeEnvironment); } } } @@ -655,8 +656,8 @@ class RedirectingFactoryBuilder extends SourceFactoryBuilder { SourceClassBuilder sourceClassBuilder, TypeEnvironment typeEnvironment) {} @override - void checkTypes( - SourceLibraryBuilder library, TypeEnvironment typeEnvironment) { + void checkTypes(SourceLibraryBuilder library, NameSpace nameSpace, + TypeEnvironment typeEnvironment) { library.checkTypesInRedirectingFactoryBuilder(this, typeEnvironment); } diff --git a/pkg/front_end/lib/src/source/source_field_builder.dart b/pkg/front_end/lib/src/source/source_field_builder.dart index 660825c240ae..1af0b9865adf 100644 --- a/pkg/front_end/lib/src/source/source_field_builder.dart +++ b/pkg/front_end/lib/src/source/source_field_builder.dart @@ -2,8 +2,8 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -import 'package:_fe_analyzer_shared/src/scanner/scanner.dart' show Token; import 'package:_fe_analyzer_shared/src/metadata/expressions.dart' as shared; +import 'package:_fe_analyzer_shared/src/scanner/scanner.dart' show Token; import 'package:kernel/ast.dart'; import 'package:kernel/class_hierarchy.dart'; import 'package:kernel/core_types.dart'; @@ -13,6 +13,7 @@ import 'package:kernel/type_environment.dart'; import '../api_prototype/lowering_predicates.dart'; import '../base/constant_context.dart' show ConstantContext; import '../base/modifiers.dart' show Modifiers; +import '../base/name_space.dart'; import '../base/problems.dart' show internalProblem; import '../base/scope.dart' show LookupScope; import '../builder/builder.dart'; @@ -652,8 +653,8 @@ class SourceFieldBuilder extends SourceMemberBuilderImpl } @override - void checkTypes( - SourceLibraryBuilder library, TypeEnvironment typeEnvironment) { + void checkTypes(SourceLibraryBuilder library, NameSpace nameSpace, + TypeEnvironment typeEnvironment) { library.checkTypesInField(this, typeEnvironment); } diff --git a/pkg/front_end/lib/src/source/source_library_builder.dart b/pkg/front_end/lib/src/source/source_library_builder.dart index e29091978250..c07e61e580a2 100644 --- a/pkg/front_end/lib/src/source/source_library_builder.dart +++ b/pkg/front_end/lib/src/source/source_library_builder.dart @@ -2009,22 +2009,8 @@ class SourceLibraryBuilder extends LibraryBuilderImpl { Iterator iterator = localMembersIterator; while (iterator.moveNext()) { Builder declaration = iterator.current; - if (declaration is SourceFieldBuilder) { - declaration.checkTypes(this, typeEnvironment); - } else if (declaration is SourceProcedureBuilder) { - List? typeParameters = declaration.typeParameters; - if (typeParameters != null && typeParameters.isNotEmpty) { - checkTypeParameterDependencies(typeParameters); - } - declaration.checkTypes(this, typeEnvironment); - if (declaration.isGetter) { - Builder? setterDeclaration = libraryNameSpace - .lookupLocalMember(declaration.name, setter: true); - if (setterDeclaration != null) { - checkGetterSetterTypes(declaration, - setterDeclaration as ProcedureBuilder, typeEnvironment); - } - } + if (declaration is SourceMemberBuilder) { + declaration.checkTypes(this, libraryNameSpace, typeEnvironment); } else if (declaration is SourceClassBuilder) { List? typeParameters = declaration.typeParameters; if (typeParameters != null && typeParameters.isNotEmpty) { diff --git a/pkg/front_end/lib/src/source/source_member_builder.dart b/pkg/front_end/lib/src/source/source_member_builder.dart index 7c2f00709890..a9cd710c6621 100644 --- a/pkg/front_end/lib/src/source/source_member_builder.dart +++ b/pkg/front_end/lib/src/source/source_member_builder.dart @@ -7,6 +7,7 @@ import 'package:kernel/class_hierarchy.dart'; import 'package:kernel/type_environment.dart'; import '../base/common.dart'; +import '../base/name_space.dart'; import '../base/problems.dart' show unsupported; import '../builder/member_builder.dart'; import '../builder/metadata_builder.dart'; @@ -49,8 +50,8 @@ abstract class SourceMemberBuilder implements MemberBuilder { SourceClassBuilder sourceClassBuilder, TypeEnvironment typeEnvironment); /// Checks the signature types of this member. - void checkTypes( - SourceLibraryBuilder library, TypeEnvironment typeEnvironment); + void checkTypes(SourceLibraryBuilder library, NameSpace nameSpace, + TypeEnvironment typeEnvironment); /// Returns `true` if this member is declared using the `augment` modifier. bool get isAugmentation; diff --git a/pkg/front_end/lib/src/source/source_procedure_builder.dart b/pkg/front_end/lib/src/source/source_procedure_builder.dart index 4092ffd8a911..252014a6676f 100644 --- a/pkg/front_end/lib/src/source/source_procedure_builder.dart +++ b/pkg/front_end/lib/src/source/source_procedure_builder.dart @@ -7,6 +7,7 @@ import 'package:kernel/type_algebra.dart'; import 'package:kernel/type_environment.dart'; import '../base/modifiers.dart'; +import '../base/name_space.dart'; import '../builder/builder.dart'; import '../builder/declaration_builders.dart'; import '../builder/formal_parameter_builder.dart'; @@ -672,13 +673,29 @@ class SourceProcedureBuilder extends SourceFunctionBuilderImpl } @override - void checkTypes( - SourceLibraryBuilder library, TypeEnvironment typeEnvironment) { - library.checkTypesInFunctionBuilder(this, typeEnvironment); + void checkTypes(SourceLibraryBuilder libraryBuilder, NameSpace nameSpace, + TypeEnvironment typeEnvironment) { + List? typeParameters = this.typeParameters; + if (typeParameters != null && typeParameters.isNotEmpty) { + libraryBuilder.checkTypeParameterDependencies(typeParameters); + } + libraryBuilder.checkTypesInFunctionBuilder(this, typeEnvironment); List? augmentations = _augmentations; if (augmentations != null) { for (SourceProcedureBuilder augmentation in augmentations) { - augmentation.checkTypes(library, typeEnvironment); + augmentation.checkTypes(libraryBuilder, nameSpace, typeEnvironment); + } + } + if (isGetter) { + if (!isClassMember) { + // Getter/setter type conflict for class members is handled in the class + // hierarchy builder. + Builder? setterDeclaration = + nameSpace.lookupLocalMember(name, setter: true); + if (setterDeclaration != null) { + libraryBuilder.checkGetterSetterTypes( + this, setterDeclaration as ProcedureBuilder, typeEnvironment); + } } } }