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

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

Issue 2805443002: Restrict `@immutable` checks to instance fields (Closed)
Patch Set: Created 3 years, 8 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 | « pkg/analyzer/lib/src/dart/error/hint_codes.dart ('k') | 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 4240441a366723fd12ca8cbcc8b76248fe90a6e6..ec01567da777e61f1b557b04243c927cdf6562ae 100644
--- a/pkg/analyzer/lib/src/generated/resolver.dart
+++ b/pkg/analyzer/lib/src/generated/resolver.dart
@@ -780,11 +780,12 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
}
/**
- * Return `true` if the given class [element] defines a non-final field.
+ * Return `true` if the given class [element] defines a non-final instance
+ * field.
*/
- bool hasNonFinalField(ClassElement element) {
+ bool hasNonFinalInstanceField(ClassElement element) {
for (FieldElement field in element.fields) {
- if (!field.isSynthetic && !field.isFinal) {
+ if (!field.isSynthetic && !field.isFinal && !field.isStatic) {
return true;
}
}
@@ -795,19 +796,19 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
* Return `true` if the given class [element] defines or inherits a
* non-final field.
*/
- bool hasOrInheritsNonFinalField(
+ bool hasOrInheritsNonFinalInstanceField(
ClassElement element, HashSet<ClassElement> visited) {
if (visited.add(element)) {
- if (hasNonFinalField(element)) {
+ if (hasNonFinalInstanceField(element)) {
return true;
}
for (InterfaceType mixin in element.mixins) {
- if (hasNonFinalField(mixin.element)) {
+ if (hasNonFinalInstanceField(mixin.element)) {
return true;
}
}
if (element.supertype != null) {
- return hasOrInheritsNonFinalField(element.supertype.element, visited);
+ return hasOrInheritsNonFinalInstanceField(element.supertype.element, visited);
}
}
return false;
@@ -815,7 +816,7 @@ class BestPracticesVerifier extends RecursiveAstVisitor<Object> {
ClassElement element = node.element;
if (isOrInheritsImmutable(element, new HashSet<ClassElement>()) &&
- hasOrInheritsNonFinalField(element, new HashSet<ClassElement>())) {
+ hasOrInheritsNonFinalInstanceField(element, new HashSet<ClassElement>())) {
_errorReporter.reportErrorForNode(HintCode.MUST_BE_IMMUTABLE, node.name);
}
}
« no previous file with comments | « pkg/analyzer/lib/src/dart/error/hint_codes.dart ('k') | pkg/analyzer/test/generated/hint_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698