b81f12a549
Change-Id: I0fa2ee2561dd0bc399d88868d790d56e6df3c94d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/134940 Commit-Queue: Bob Nystrom <rnystrom@google.com> Auto-Submit: Bob Nystrom <rnystrom@google.com> Reviewed-by: Lasse R.H. Nielsen <lrn@google.com>
36 lines
1013 B
Dart
36 lines
1013 B
Dart
// Copyright (c) 2018, 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.
|
|
|
|
// Test that various invalid uses of `yield` are disallowed.
|
|
|
|
import "dart:async";
|
|
import "package:expect/expect.dart";
|
|
import "package:async_helper/async_helper.dart";
|
|
|
|
var yield = 42;
|
|
|
|
main() async {
|
|
asyncStart();
|
|
Stream<String> f() async* {
|
|
// Invalid syntax.
|
|
yield ("a", "b"); //# 01: syntax error
|
|
yield yield "twice"; //# 02: syntax error
|
|
|
|
// Valid but curious syntax.
|
|
yield throw "throw"; //# 03: runtime error
|
|
|
|
// Type error.
|
|
yield* "one"; //# 04: compile-time error
|
|
|
|
label: yield "ok";
|
|
}
|
|
var completer = Completer();
|
|
f().listen(completer.complete, onError: completer.completeError,
|
|
onDone: () {
|
|
if (!completer.isCompleted) completer.completeError("not ok?");
|
|
});
|
|
Expect.equals("ok", await completer.future);
|
|
asyncEnd();
|
|
}
|