mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 17:59:39 +00:00
[wildcard-variables] Add async rethrow test and wildcard patterns.
Fix follow up comments with an async rethrow test. Tests that wildcard patterns still work while mixed with wildcard variables. Bug: https://github.com/dart-lang/sdk/issues/55652 Change-Id: If6ab4de68ff27ad51215427a7183f1aed7229947 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/367501 Reviewed-by: Erik Ernst <eernst@google.com> Commit-Queue: Kallen Tu <kallentu@google.com>
This commit is contained in:
parent
8e405fdff7
commit
70b9b4637b
|
@ -0,0 +1,76 @@
|
|||
// Copyright (c) 2024, 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.
|
||||
|
||||
// Tests multiple catch clause wildcard variable declarations with rethrow and
|
||||
// awaits.
|
||||
|
||||
// SharedOptions=--enable-experiment=wildcard-variables
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
import "package:async_helper/async_helper.dart";
|
||||
|
||||
void main() async {
|
||||
asyncStart();
|
||||
test().then((_) => asyncEnd());
|
||||
}
|
||||
|
||||
Future<void> test() async {
|
||||
var tryValue = Future<int>.value(1);
|
||||
var catchValue = Future<int>.value(1);
|
||||
|
||||
var error = StateError("State bad!");
|
||||
var stack = StackTrace.fromString("My stack trace");
|
||||
var caught = false;
|
||||
|
||||
// Multiple wildcard catch clause variables.
|
||||
try {
|
||||
try {
|
||||
await tryValue;
|
||||
Error.throwWithStackTrace(error, stack);
|
||||
} on StateError catch (_, _) {
|
||||
await catchValue;
|
||||
caught = true;
|
||||
rethrow;
|
||||
}
|
||||
} on StateError catch (e, s) {
|
||||
Expect.isTrue(caught);
|
||||
Expect.identical(error, e);
|
||||
Expect.equals(stack.toString(), s.toString());
|
||||
Expect.equals(stack.toString(), e.stackTrace.toString());
|
||||
}
|
||||
|
||||
// Single wildcard catch clause variable.
|
||||
try {
|
||||
try {
|
||||
await tryValue;
|
||||
Error.throwWithStackTrace(error, stack);
|
||||
} on StateError catch (_) {
|
||||
await catchValue;
|
||||
caught = true;
|
||||
rethrow;
|
||||
}
|
||||
} on StateError catch (e, s) {
|
||||
Expect.isTrue(caught);
|
||||
Expect.identical(error, e);
|
||||
Expect.equals(stack.toString(), s.toString());
|
||||
Expect.equals(stack.toString(), e.stackTrace.toString());
|
||||
}
|
||||
|
||||
try {
|
||||
try {
|
||||
await tryValue;
|
||||
Error.throwWithStackTrace(error, stack);
|
||||
} on StateError catch (_, s) {
|
||||
await catchValue;
|
||||
Expect.equals(stack.toString(), s.toString());
|
||||
caught = true;
|
||||
rethrow;
|
||||
}
|
||||
} on StateError catch (e, s) {
|
||||
Expect.isTrue(caught);
|
||||
Expect.identical(error, e);
|
||||
Expect.equals(stack.toString(), s.toString());
|
||||
Expect.equals(stack.toString(), e.stackTrace.toString());
|
||||
}
|
||||
}
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
// SharedOptions=--enable-experiment=wildcard-variables
|
||||
|
||||
import 'package:async_helper/async_helper.dart';
|
||||
|
||||
void main() async {
|
||||
// Multiple for-loop wildcard declarations.
|
||||
for (int _ = 0, _ = 2;;) {
|
||||
|
@ -15,6 +17,11 @@ void main() async {
|
|||
var list = [];
|
||||
for (var _ in list) {}
|
||||
|
||||
asyncStart();
|
||||
streamTest().then((_) => asyncEnd());
|
||||
}
|
||||
|
||||
Future streamTest() async {
|
||||
var stream = Stream.empty();
|
||||
await for (var _ in stream) {}
|
||||
}
|
||||
|
|
|
@ -22,13 +22,14 @@ class InstanceMember {
|
|||
int _ = 2;
|
||||
const _ = 2;
|
||||
int _() => 2;
|
||||
_ = 3;
|
||||
Expect.equals(3, _);
|
||||
var (_, _) = (3, '4');
|
||||
Expect.equals(2, _);
|
||||
|
||||
int _() => 2;
|
||||
_ = 4;
|
||||
Expect.equals(4, _);
|
||||
|
||||
int foo<_>([int _ = 5]) => _;
|
||||
Expect.equals(3, foo());
|
||||
Expect.equals(4, foo());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,10 +42,13 @@ class StaticMember {
|
|||
const _ = 2;
|
||||
const _ = _ - 1;
|
||||
int _() => 2;
|
||||
_ = 3;
|
||||
Expect.equals(3, _);
|
||||
var (_, _) = (3, '4');
|
||||
Expect.equals(2, _);
|
||||
|
||||
_ = 4;
|
||||
Expect.equals(4, _);
|
||||
|
||||
int foo<_>([int _ = _ + 1]) => _;
|
||||
Expect.equals(3, foo());
|
||||
Expect.equals(4, foo());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,8 @@ void main() {
|
|||
int _ = 1;
|
||||
const _ = 1;
|
||||
int _() => 1;
|
||||
var (_, _) = (3, '4');
|
||||
|
||||
Expect.equals(2, _(1));
|
||||
}
|
||||
|
||||
|
@ -23,6 +25,8 @@ class Clas<_> {
|
|||
int _ = 1;
|
||||
const _ = 1;
|
||||
int _() => 1;
|
||||
var (_, _) = (3, '4');
|
||||
|
||||
Expect.equals(2, _(1));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -30,7 +30,11 @@ class CConst {
|
|||
final _ = _;
|
||||
const _ = _;
|
||||
int _() => 1;
|
||||
var (_, _) = (3, '4');
|
||||
Expect.equals(42, _);
|
||||
|
||||
int foo<_>([String _ = "$_"]) => _;
|
||||
_ = foo();
|
||||
foo();
|
||||
Expect.equals(42, _);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,16 +15,21 @@ void main() {
|
|||
Clas().member();
|
||||
|
||||
int _ = _;
|
||||
int _ = 2;
|
||||
_ = 3;
|
||||
Expect.equals(3, _);
|
||||
int _ = 3;
|
||||
var (_, _) = (3, '4');
|
||||
Expect.equals(2, _);
|
||||
|
||||
_ = 4;
|
||||
Expect.equals(4, _);
|
||||
}
|
||||
|
||||
class Clas<_> {
|
||||
void member<_>() {
|
||||
int _ = _;
|
||||
int _ = 2;
|
||||
int _ = 3;
|
||||
var (_, _) = (3, '4');
|
||||
Expect.equals(2, _);
|
||||
|
||||
_ = 4;
|
||||
Expect.equals(4, _);
|
||||
|
||||
|
|
Loading…
Reference in a new issue