Files
sdk/tests/language/sync_star/generator2_test.dart
Erik Ernst 0fcdc08e60 Change language tests to avoid unintended syntax errors
The new feature 'declaring constructors' will change the syntax such
that it is an error for a non-declaring formal parameter declaration
to have the modifier `final`, and it is an error to use `var` as a
replacement for a type annotation (but the type annotation can still
be omitted entirely). This CL removes those modifiers such that the
tests will not start failing on things that aren't errors any more.

Change-Id: Ie6628f66eca696b28900759d8234b814033b4027
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/456740
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Commit-Queue: Erik Ernst <eernst@google.com>
2025-10-27 01:35:09 -07:00

69 lines
1.9 KiB
Dart

// Copyright (c) 2015, 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.
// Formatting can break multitests, so don't format them.
// dart format off
// Simple test program for sync* generator functions.
import "package:expect/expect.dart";
import "dart:async";
var sync = "topLevelSync";
var async = "topLevelAsync";
var await = "topLevelAwait";
var yield = "topLevelYield";
test01() sync* {
var yield = 0; // //# 01: syntax error
var await = 0; // //# 02: syntax error
bool yield() => false; //# 04: syntax error
bool await() => false; //# 05: syntax error
var x1 = sync;
var x3 = await; // //# 08: syntax error
var x4 = await 55; // //# 09: compile-time error
var x4 = yield; // //# 10: syntax error
var stream = new Stream.fromIterable([1, 2, 3]);
await for (var e in stream) print(e); // //# 11: compile-time error
}
test02() sync* {
yield 12321;
return null; // //# 20: compile-time error
}
test03() sync* => null; // //# 30: syntax error
get test04 sync* => null; // //# 40: syntax error
set test04(a) sync* { print(a); } // //# 41: compile-time error
class K {
K() sync* {} // //# 50: compile-time error
get nix sync* {}
get garnix sync* => null; // //# 51: syntax error
set etwas(z) sync* { } // //# 52: compile-time error
sync() sync* {
yield sync; // Yields a tear-off of the sync() method.
}
}
main() {
var x;
x = test01();
Expect.equals("()", x.toString());
x = test02();
test03(); //# 30: continued
Expect.equals("(12321)", x.toString());
x = test04; // //# 40: continued
test04 = x; // //# 41: continued
x = new K();
print(x.garnix); //# 51: continued
x.etwas = null; //# 52: continued
print(x.sync().toList());
Expect.equals(1, x.sync().length);
// Expect.isTrue(x.sync().single is Function);
}