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

Unified Diff: pkg/analyzer/test/generated/hint_code_test.dart

Issue 2775863004: Add error checking for the immutable annotation (issue 27750) (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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/hint_code_test.dart
diff --git a/pkg/analyzer/test/generated/hint_code_test.dart b/pkg/analyzer/test/generated/hint_code_test.dart
index 013ffe281867cbdeca13e8d22ea0a64e127811ab..5398653f8f9d16ac6b108048d7fdc3448e8d8fb6 100644
--- a/pkg/analyzer/test/generated/hint_code_test.dart
+++ b/pkg/analyzer/test/generated/hint_code_test.dart
@@ -31,6 +31,7 @@ class HintCodeTest extends ResolverTestCase {
library meta;
const _Factory factory = const _Factory();
+const Immutable immutable = const Immutable();
const _Literal literal = const _Literal();
const _MustCallSuper mustCallSuper = const _MustCallSuper();
const _Protected protected = const _Protected();
@@ -40,6 +41,10 @@ class Required {
const Required([this.reason]);
}
+class Immutable {
+ final String reason;
+ const Immutable([this.reason]);
+}
class _Factory {
const _Factory();
}
@@ -1362,6 +1367,19 @@ main() {
verify([source]);
}
+ test_invalidImmutableAnnotation_method() async {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+class A {
+ @immutable
+ void m() {}
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [HintCode.INVALID_IMMUTABLE_ANNOTATION]);
+ verify([source]);
+ }
+
test_invalidUseOfProtectedMember_closure() async {
Source source = addNamedSource(
'/lib1.dart',
@@ -1975,6 +1993,48 @@ class A {
verify([source]);
}
+ test_mustBeImmutable_direct() async {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+@immutable
+class A {
+ int x;
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [HintCode.MUST_BE_IMMUTABLE]);
+ verify([source]);
+ }
+
+ test_mustBeImmutable_extends() async {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+@immutable
+class A {}
+class B extends A {
+ int x;
+}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [HintCode.MUST_BE_IMMUTABLE]);
+ verify([source]);
+ }
+
+ test_mustBeImmutable_fromMixin() async {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+@immutable
+class A {}
+class B {
+ int x;
+}
+class C extends A with B {}
+''');
+ await computeAnalysisResult(source);
+ assertErrors(source, [HintCode.MUST_BE_IMMUTABLE]);
+ verify([source]);
+ }
+
test_mustCallSuper() async {
Source source = addSource(r'''
import 'package:meta/meta.dart';
« no previous file with comments | « pkg/analyzer/lib/src/generated/resolver.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698