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

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

Issue 890253003: Report a compile-time error if async/sync/yield used as an identifier. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 11 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/parser.dart ('k') | tests/language/language_analyzer2.status » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/test/generated/compile_time_error_code_test.dart
diff --git a/pkg/analyzer/test/generated/compile_time_error_code_test.dart b/pkg/analyzer/test/generated/compile_time_error_code_test.dart
index 5df81b0bf003ee0c8d9644e48e5ef7777c6da79b..095c419a8e08f26bbb0b4024d228303836f2fb0b 100644
--- a/pkg/analyzer/test/generated/compile_time_error_code_test.dart
+++ b/pkg/analyzer/test/generated/compile_time_error_code_test.dart
@@ -246,6 +246,300 @@ class N {}''');
verify([source]);
}
+ void test_async_used_as_identifier_in_annotation() {
+ Source source = addSource('''
+const int async = 0;
+f() async {
+ g(@async x) {}
+ g(0);
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_argument_label() {
+ Source source = addSource('''
+@proxy
+class C {}
+f() async {
+ new C().g(async: 0);
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ // Note: we don't call verify([source]) because verify() doesn't understand
+ // about @proxy.
+ }
+
+ void test_async_used_as_identifier_in_async_method() {
+ Source source = addSource('''
+f() async {
+ var async = 1;
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_async_star_method() {
+ Source source = addSource('''
+f() async* {
+ var async = 1;
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_break_statement() {
+ Source source = addSource('''
+f() async {
+ while (true) {
+ break async;
+ }
+}
+''');
+ resolve(source);
+ assertErrors(
+ source,
+ [
+ ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER,
+ CompileTimeErrorCode.LABEL_UNDEFINED]);
+ // Note: we don't call verify([source]) because the reference to the
+ // "async" label is unresolved.
+ }
+
+ void test_async_used_as_identifier_in_cascaded_invocation() {
+ Source source = addSource('''
+class C {
+ int async() => 1;
+}
+f() async {
+ return new C()..async();
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_cascaded_setter_invocation() {
+ Source source = addSource('''
+class C {
+ void set async(int i) {}
+}
+f() async {
+ return new C()..async = 1;
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_catch_exception_argument() {
+ Source source = addSource('''
+g() {}
+f() async {
+ try {
+ g();
+ } catch (async) { }
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_catch_stacktrace_argument() {
+ Source source = addSource('''
+g() {}
+f() async {
+ try {
+ g();
+ } catch (e, async) { }
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_continue_statement() {
+ Source source = addSource('''
+f() async {
+ while (true) {
+ continue async;
+ }
+}
+''');
+ resolve(source);
+ assertErrors(
+ source,
+ [
+ ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER,
+ CompileTimeErrorCode.LABEL_UNDEFINED]);
+ // Note: we don't call verify([source]) because the reference to the
+ // "async" label is unresolved.
+ }
+
+ void test_async_used_as_identifier_in_for_statement() {
+ Source source = addSource('''
+var async;
+f() async {
+ for (async in []) {}
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_formal_parameter_name() {
+ Source source = addSource('''
+f() async {
+ g(int async) {}
+ g(0);
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_getter_name() {
+ Source source = addSource('''
+class C {
+ int get async => 1;
+}
+f() async {
+ return new C().async;
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_invocation() {
+ Source source = addSource('''
+class C {
+ int async() => 1;
+}
+f() async {
+ return new C().async();
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_local_function_name() {
+ Source source = addSource('''
+f() async {
+ int async() => null;
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_prefix() {
+ Source source = addSource('''
+import 'dart:async' as async;
+f() async {
+ return new async.Future.value(0);
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_setter_name() {
+ Source source = addSource('''
+class C {
+ void set async(int i) {}
+}
+f() async {
+ new C().async = 1;
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_statement_label() {
+ Source source = addSource('''
+f() async {
+ async: g();
+}
+g() {}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_string_interpolation() {
+ Source source = addSource(r'''
+int async = 1;
+f() async {
+ return "$async";
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_suffix() {
+ addNamedSource("/lib1.dart", r'''
+library lib1;
+int async;
+''');
+ Source source = addSource('''
+import 'lib1.dart' as l;
+f() async {
+ return l.async;
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_switch_label() {
+ Source source = addSource('''
+f() async {
+ switch (0) {
+ async: case 0: break;
+ }
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_async_used_as_identifier_in_sync_star_method() {
+ Source source = addSource('''
+f() sync* {
+ var async = 1;
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
void test_asyncForInWrongContext() {
Source source = addSource(r'''
f(list) {
@@ -257,6 +551,39 @@ f(list) {
verify([source]);
}
+ void test_await_used_as_identifier_in_async_method() {
+ Source source = addSource('''
+f() async {
+ var await = 1;
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_await_used_as_identifier_in_async_star_method() {
+ Source source = addSource('''
+f() async* {
+ var await = 1;
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_await_used_as_identifier_in_sync_star_method() {
+ Source source = addSource('''
+f() sync* {
+ var await = 1;
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
void test_builtInIdentifierAsMixinName_classTypeAlias() {
Source source = addSource(r'''
class A {}
@@ -653,8 +980,7 @@ library root;
import 'lib1.dart' deferred as a;
main() {
const a.A();
-}'''],
- <ErrorCode>[CompileTimeErrorCode.CONST_DEFERRED_CLASS]);
+}'''], <ErrorCode>[CompileTimeErrorCode.CONST_DEFERRED_CLASS]);
}
void test_constDeferredClass_namedConstructor() {
@@ -667,8 +993,7 @@ library root;
import 'lib1.dart' deferred as a;
main() {
const a.A.b();
-}'''],
- <ErrorCode>[CompileTimeErrorCode.CONST_DEFERRED_CLASS]);
+}'''], <ErrorCode>[CompileTimeErrorCode.CONST_DEFERRED_CLASS]);
}
void test_constEval_newInstance_constConstructor() {
@@ -5347,6 +5672,39 @@ class A {
verify([source]);
}
+ void test_yield_used_as_identifier_in_async_method() {
+ Source source = addSource('''
+f() async {
+ var yield = 1;
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_yield_used_as_identifier_in_async_star_method() {
+ Source source = addSource('''
+f() async* {
+ var yield = 1;
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
+ void test_yield_used_as_identifier_in_sync_star_method() {
+ Source source = addSource('''
+f() sync* {
+ var yield = 1;
+}
+''');
+ resolve(source);
+ assertErrors(source, [ParserErrorCode.ASYNC_KEYWORD_USED_AS_IDENTIFIER]);
+ verify([source]);
+ }
+
void _check_constEvalThrowsException_binary_null(String expr, bool resolved) {
Source source = addSource("const C = $expr;");
resolve(source);
« no previous file with comments | « pkg/analyzer/lib/src/generated/parser.dart ('k') | tests/language/language_analyzer2.status » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698