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

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

Issue 1173523002: Fix analyzer's handling of import prefixes not followed by '.'. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 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
Index: pkg/analyzer/test/generated/static_type_warning_code_test.dart
diff --git a/pkg/analyzer/test/generated/static_type_warning_code_test.dart b/pkg/analyzer/test/generated/static_type_warning_code_test.dart
index 8e5a303012818bf0bed39cb875dbb5cc0957ab6c..dd50b9328f0abf3d35f0c324b12874c7b884c364 100644
--- a/pkg/analyzer/test/generated/static_type_warning_code_test.dart
+++ b/pkg/analyzer/test/generated/static_type_warning_code_test.dart
@@ -54,6 +54,47 @@ f() {}''');
assertErrors(source, [StaticWarningCode.AMBIGUOUS_IMPORT]);
}
+ void test_assignment_to_prefix_in_method() {
+ // If p is an import prefix, then within a method body, p = expr should be
+ // considered equivalent to this.p = expr.
+ addNamedSource("/lib.dart", r'''
+library lib;
+''');
+ Source source = addSource(r'''
+import 'lib.dart' as p;
+class C {
+ f() {
+ p = 0;
+ }
+}
+''');
+ resolve(source);
+ assertErrors(source, [
+ StaticWarningCode.UNDEFINED_IDENTIFIER,
+ HintCode.UNUSED_IMPORT
+ ]);
+ }
+
+ void test_assignment_to_prefix_not_in_method() {
+ // If p is an import prefix, then outside a method body, p = expr should be
+ // considered equivalent to this.p = expr (and hence should result in a
+ // static warning).
+ addNamedSource("/lib.dart", r'''
+library lib;
+''');
+ Source source = addSource(r'''
+import 'lib.dart' as p;
+f() {
+ p = 0;
+}
+''');
+ resolve(source);
+ assertErrors(source, [
+ StaticWarningCode.UNDEFINED_IDENTIFIER,
+ HintCode.UNUSED_IMPORT
+ ]);
+ }
+
void test_await_flattened() {
Source source = addSource('''
import 'dart:async';
@@ -1771,6 +1812,46 @@ class B extends A {
assertErrors(source, [StaticTypeWarningCode.UNDEFINED_SUPER_SETTER]);
}
+ void test_unqualified_invocation_of_prefix_in_method() {
+ // If p is an import prefix, then within a method body, p() should be
+ // considered equivalent to this.p().
+ addNamedSource("/lib.dart", r'''
+library lib;
+''');
+ Source source = addSource(r'''
+import 'lib.dart' as p;
+class C {
+ f() {
+ p();
+ }
+}
+''');
+ resolve(source);
+ assertErrors(source, [
+ StaticTypeWarningCode.UNDEFINED_METHOD,
+ HintCode.UNUSED_IMPORT
+ ]);
+ verify([source]);
+ }
+
+ void test_unqualified_invocation_of_prefix_not_in_method() {
+ // If p is an import prefix, then outside a method body, p() should be
+ // considered equivalent to this.p() (and hence should result in a static
+ // warning).
+ addNamedSource("/lib.dart", r'''
+library lib;
+''');
+ Source source = addSource(r'''
+import 'lib.dart' as p;
+f() {
+ p();
+}
+''');
+ resolve(source);
+ assertErrors(source, [StaticTypeWarningCode.UNDEFINED_FUNCTION]);
+ verify([source]);
+ }
+
void test_unqualifiedReferenceToNonLocalStaticMember_getter() {
Source source = addSource(r'''
class A {
« no previous file with comments | « pkg/analyzer/test/generated/non_error_resolver_test.dart ('k') | pkg/analyzer/test/generated/static_warning_code_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698