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

Unified Diff: pkg/analyzer/lib/src/generated/resolver.dart

Issue 2032363003: Fix @protected access check from within defining class (#26614). (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/hint_code_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/resolver.dart
diff --git a/pkg/analyzer/lib/src/generated/resolver.dart b/pkg/analyzer/lib/src/generated/resolver.dart
index ca74f2a7e283e3108b00de4877b8e7af8d9c185e..985abf96edd58424b25e46b8f92b956a18a9a03e 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -700,7 +700,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
}
ClassElement invokingClass = decl.element?.enclosingElement;
- if (!_hasSuperType(invokingClass, definingClass.type)) {
+ if (!_hasTypeOrSuperType(invokingClass, definingClass.type)) {
_errorReporter.reportErrorForNode(
HintCode.INVALID_USE_OF_PROTECTED_MEMBER,
node,
@@ -729,7 +729,8 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
HintCode.INVALID_USE_OF_PROTECTED_MEMBER,
identifier,
[identifier.name.toString(), definingClass.name]);
- } else if (!_hasSuperType(accessingClass.element, definingClass.type)) {
+ } else if (!_hasTypeOrSuperType(
+ accessingClass.element, definingClass.type)) {
_errorReporter.reportErrorForNode(
HintCode.INVALID_USE_OF_PROTECTED_MEMBER,
identifier,
@@ -1006,26 +1007,9 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
// return false;
// }
- bool _hasSuperClassOrMixin(ClassElement element, InterfaceType type) {
- List<ClassElement> seenClasses = <ClassElement>[];
- while (element != null && !seenClasses.contains(element)) {
- if (element.type == type) {
- return true;
- }
-
- if (element.mixins.any((InterfaceType t) => t == type)) {
- return true;
- }
-
- seenClasses.add(element);
- element = element.supertype?.element;
- }
-
- return false;
- }
-
- bool _hasSuperType(ClassElement element, InterfaceType type) =>
- element != null && element.allSupertypes.contains(type);
+ bool _hasTypeOrSuperType(ClassElement element, InterfaceType type) =>
+ element != null &&
+ (element.type == type || element.allSupertypes.contains(type));
/**
* Given a parenthesized expression, this returns the parent (or recursively grand-parent) of the
« no previous file with comments | « no previous file | pkg/analyzer/test/generated/hint_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698