Files
sdk/tests/language_2/known_identifier_usage_error_test.dart
T
Lasse R.H. Nielsen eca6c8953f Allow async as an identifier everywhere.
Fixes #37063

Bug: http://dartbug.com/37063
Change-Id: I2253c3088fbe33eca1072f2480cf0cf3cc363362
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/103524
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
2019-05-24 08:21:14 +00:00

74 lines
2.0 KiB
Dart

// Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// The identifiers listed below are mentioned in the grammar, but none of
// them is a reserved word or a built-in identifier. Such an identifier can
// be used just like all other identifiers, with the exceptions mentioned
// below. Here are said 'known' identifiers:
//
// `async`, `await`, `hide`, `of`, `on`, `show`, `sync`, `yield`
//
// The following exceptions apply:
//
// It is a compile-time error to use `async`, `await`, or `yield` as an
// identifier in the body of a function marked `async`, `async*`, or
// `sync*`.
//
// It is a compile-time error if an asynchronous for-in appears inside a
// synchronous function.
import 'dart:async';
Future<int> f1() async {
int async = 1;
int await = 1; //# 02: syntax error
int yield = 1; //# 03: syntax error
Stream<int> s = new Stream<int>.fromFuture(new Future<int>.value(1));
await for (int i in s) {
return i + 1;
}
}
Stream<int> f2() async* {
int async = 1;
int await = 1; //# 05: syntax error
int yield = 1; //# 06: syntax error
Stream<int> s = new Stream<int>.fromFuture(new Future<int>.value(1));
await for (var i in s) {
yield i + 1;
}
}
Iterable<int> f3() sync* {
int async = 1;
int await = 1; //# 08: syntax error
int yield = 1; //# 09: syntax error
Stream<int> s = new Stream<int>.fromFuture(new Future<int>.value(1));
await for (int i in s) { //# 10: compile-time error
yield i + 1; //# 10: continued
} //# 10: continued
}
int f4() {
int async = 1;
int await = 1;
int yield = 1;
Stream s = new Stream<int>.fromFuture(new Future<int>.value(1));
await for (int i in s) { //# 11: compile-time error
return i + 1; //# 11: continued
} //# 11: continued
}
main() {
Future<int> f = f1();
Stream s = f2();
Iterable<int> i = f3();
int x = f4();
}