Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1499)

Side by Side Diff: pkg/analyzer/lib/src/generated/error_verifier.dart

Issue 2716133002: Revert "Add error for mixins defining conflicting private names (issue 28809)" (Closed)
Patch Set: Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library analyzer.src.generated.error_verifier; 5 library analyzer.src.generated.error_verifier;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import "dart:math" as math; 8 import "dart:math" as math;
9 9
10 import 'package:analyzer/dart/ast/ast.dart'; 10 import 'package:analyzer/dart/ast/ast.dart';
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
479 _checkForExtendsDeferredClass(extendsClause); 479 _checkForExtendsDeferredClass(extendsClause);
480 _checkForImplementsDeferredClass(implementsClause); 480 _checkForImplementsDeferredClass(implementsClause);
481 _checkForNonAbstractClassInheritsAbstractMember(node.name); 481 _checkForNonAbstractClassInheritsAbstractMember(node.name);
482 _checkForInconsistentMethodInheritance(); 482 _checkForInconsistentMethodInheritance();
483 _checkForRecursiveInterfaceInheritance(_enclosingClass); 483 _checkForRecursiveInterfaceInheritance(_enclosingClass);
484 _checkForConflictingGetterAndMethod(); 484 _checkForConflictingGetterAndMethod();
485 _checkForConflictingInstanceGetterAndSuperclassMember(); 485 _checkForConflictingInstanceGetterAndSuperclassMember();
486 _checkImplementsSuperClass(node); 486 _checkImplementsSuperClass(node);
487 _checkImplementsFunctionWithoutCall(node); 487 _checkImplementsFunctionWithoutCall(node);
488 _checkForMixinHasNoConstructors(node); 488 _checkForMixinHasNoConstructors(node);
489 _checkForMixinWithConflictingPrivateMember(node);
490 } 489 }
491 } 490 }
492 visitClassDeclarationIncrementally(node); 491 visitClassDeclarationIncrementally(node);
493 _checkForFinalNotInitializedInClass(node); 492 _checkForFinalNotInitializedInClass(node);
494 _checkForDuplicateDefinitionInheritance(); 493 _checkForDuplicateDefinitionInheritance();
495 _checkForConflictingInstanceMethodSetter(node); 494 _checkForConflictingInstanceMethodSetter(node);
496 _checkForBadFunctionUse(node); 495 _checkForBadFunctionUse(node);
497 return super.visitClassDeclaration(node); 496 return super.visitClassDeclaration(node);
498 } finally { 497 } finally {
499 _isInNativeClass = false; 498 _isInNativeClass = false;
(...skipping 4384 matching lines...) Expand 10 before | Expand all | Expand 10 after
4884 if (!enableSuperMixins && mixinElement.hasReferenceToSuper) { 4883 if (!enableSuperMixins && mixinElement.hasReferenceToSuper) {
4885 _errorReporter.reportErrorForNode( 4884 _errorReporter.reportErrorForNode(
4886 CompileTimeErrorCode.MIXIN_REFERENCES_SUPER, 4885 CompileTimeErrorCode.MIXIN_REFERENCES_SUPER,
4887 mixinName, 4886 mixinName,
4888 [mixinElement.name]); 4887 [mixinElement.name]);
4889 } 4888 }
4890 return false; 4889 return false;
4891 } 4890 }
4892 4891
4893 /** 4892 /**
4894 * Check for the declaration of a mixin from a library other than the current
4895 * library that defines a private member that conflicts with a private name
4896 * from the same library but from a superclass or a different mixin.
4897 */
4898 void _checkForMixinWithConflictingPrivateMember(ClassDeclaration node) {
4899 WithClause withClause = node.withClause;
4900 if (withClause == null) {
4901 return;
4902 }
4903 DartType declaredSupertype = node.extendsClause?.superclass?.type;
4904 if (declaredSupertype is! InterfaceType) {
4905 return;
4906 }
4907 InterfaceType superclass = declaredSupertype;
4908 Map<LibraryElement, Map<String, String>> mixedInNames =
4909 <LibraryElement, Map<String, String>>{};
4910
4911 /**
4912 * Report an error and return `true` if the given [name] is a private name
4913 * (which is defined in the given [library]) and it conflicts with another
4914 * definition of that name inherited from the superclass.
4915 */
4916 bool isConflictingName(
4917 String name, LibraryElement library, TypeName typeName) {
4918 if (Identifier.isPrivateName(name)) {
4919 Map<String, String> names =
4920 mixedInNames.putIfAbsent(library, () => <String, String>{});
4921 if (names.containsKey(name)) {
4922 _errorReporter.reportErrorForNode(
4923 CompileTimeErrorCode.PRIVATE_COLLISION_IN_MIXIN_APPLICATION,
4924 typeName,
4925 [name, typeName.name.name, names[name]]);
4926 return true;
4927 }
4928 names[name] = typeName.name.name;
4929 ExecutableElement inheritedMember =
4930 superclass.lookUpMethod(name, library) ??
4931 superclass.lookUpGetter(name, library) ??
4932 superclass.lookUpSetter(name, library);
4933 if (inheritedMember != null) {
4934 _errorReporter.reportErrorForNode(
4935 CompileTimeErrorCode.PRIVATE_COLLISION_IN_MIXIN_APPLICATION,
4936 typeName, [
4937 name,
4938 typeName.name.name,
4939 inheritedMember.enclosingElement.name
4940 ]);
4941 return true;
4942 }
4943 }
4944 return false;
4945 }
4946
4947 for (TypeName mixinType in withClause.mixinTypes) {
4948 DartType type = mixinType.type;
4949 if (type is InterfaceType) {
4950 LibraryElement library = type.element.library;
4951 if (library != _currentLibrary) {
4952 for (PropertyAccessorElement accessor in type.accessors) {
4953 if (isConflictingName(accessor.name, library, mixinType)) {
4954 return;
4955 }
4956 }
4957 for (MethodElement method in type.methods) {
4958 if (isConflictingName(method.name, library, mixinType)) {
4959 return;
4960 }
4961 }
4962 }
4963 }
4964 }
4965 }
4966
4967 /**
4968 * Verify that the given [constructor] has at most one 'super' initializer. 4893 * Verify that the given [constructor] has at most one 'super' initializer.
4969 * 4894 *
4970 * See [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS]. 4895 * See [CompileTimeErrorCode.MULTIPLE_SUPER_INITIALIZERS].
4971 */ 4896 */
4972 void _checkForMultipleSuperInitializers(ConstructorDeclaration constructor) { 4897 void _checkForMultipleSuperInitializers(ConstructorDeclaration constructor) {
4973 bool hasSuperInitializer = false; 4898 bool hasSuperInitializer = false;
4974 for (ConstructorInitializer initializer in constructor.initializers) { 4899 for (ConstructorInitializer initializer in constructor.initializers) {
4975 if (initializer is SuperConstructorInvocation) { 4900 if (initializer is SuperConstructorInvocation) {
4976 if (hasSuperInitializer) { 4901 if (hasSuperInitializer) {
4977 _errorReporter.reportErrorForNode( 4902 _errorReporter.reportErrorForNode(
(...skipping 2178 matching lines...) Expand 10 before | Expand all | Expand 10 after
7156 class _InvocationCollector extends RecursiveAstVisitor { 7081 class _InvocationCollector extends RecursiveAstVisitor {
7157 final List<String> superCalls = <String>[]; 7082 final List<String> superCalls = <String>[];
7158 7083
7159 @override 7084 @override
7160 visitMethodInvocation(MethodInvocation node) { 7085 visitMethodInvocation(MethodInvocation node) {
7161 if (node.target is SuperExpression) { 7086 if (node.target is SuperExpression) {
7162 superCalls.add(node.methodName.name); 7087 superCalls.add(node.methodName.name);
7163 } 7088 }
7164 } 7089 }
7165 } 7090 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/src/error/codes.dart ('k') | pkg/analyzer/test/generated/compile_time_error_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698