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

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

Issue 1730993003: Validation of @protected property accesses. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 10 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
Index: pkg/analyzer/test/generated/resolver_test.dart
diff --git a/pkg/analyzer/test/generated/resolver_test.dart b/pkg/analyzer/test/generated/resolver_test.dart
index 9e9d5f3359c2d331425625040aff73838f06efc9..1e619745338b2ce9f8049563d3fc05289ed821c1 100644
--- a/pkg/analyzer/test/generated/resolver_test.dart
+++ b/pkg/analyzer/test/generated/resolver_test.dart
@@ -3332,7 +3332,22 @@ main() {
verify([source]);
}
- void test_invalidUseOfProtectedMember_1() {
+ void test_invalidUseOfProtectedMember_field() {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+class A {
+ @protected
+ int a;
+}
+abstract class B implements A {
+ int b() => a;
+}''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]);
+ verify([source]);
+ }
+
+ void test_invalidUseOfProtectedMember_function() {
Source source = addSource(r'''
import 'package:meta/meta.dart';
class A {
@@ -3347,7 +3362,38 @@ main() {
verify([source]);
}
- void test_invalidUseOfProtectedMember_2() {
+ void test_invalidUseOfProtectedMember_getter() {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+class A {
+ @protected
+ int get a => 42;
+}
+abstract class B implements A {
+ int b() => a;
+}''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]);
+ verify([source]);
+ }
+
+ void test_invalidUseOfProtectedMember_message() {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+class A {
+ @protected
+ void a(){ }
+}
+class B {
+ void b() => new A().a();
+}''');
+ List<AnalysisError> errors = analysisContext2.computeErrors(source);
+ expect(errors, hasLength(1));
+ expect(errors[0].message,
+ "The member 'a' can only be used within instance members of subclasses of 'A'");
+ }
+
+ void test_invalidUseOfProtectedMember_method_1() {
Source source = addSource(r'''
import 'package:meta/meta.dart';
class A {
@@ -3362,7 +3408,7 @@ class B {
verify([source]);
}
- void test_invalidUseOfProtectedMember_3() {
+ void test_invalidUseOfProtectedMember_method_2() {
Source source = addSource(r'''
import 'package:meta/meta.dart';
class A {
@@ -3421,6 +3467,41 @@ class B extends A {
verify([source]);
}
+ void test_invalidUseOfProtectedMember_OK_4() {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+class A {
+ @protected
+ void a(){ }
+}
+class B extends A {
+ void a() => a();
+}
+main() {
+ new B().a();
+}''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, []);
+ verify([source]);
+ }
+
+ void test_invalidUseOfProtectedMember_setter() {
+ Source source = addSource(r'''
+import 'package:meta/meta.dart';
+class A {
+ @protected
+ void set a(int i) { }
+}
+abstract class B implements A {
+ b(int i) {
+ a = i;
+ }
+}''');
+ computeLibrarySourceErrors(source);
+ assertErrors(source, [HintCode.INVALID_USE_OF_PROTECTED_MEMBER]);
+ verify([source]);
+ }
+
void test_isDouble() {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.dart2jsHint = true;
« pkg/analyzer/lib/src/generated/resolver.dart ('K') | « 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