mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 22:01:19 +00:00
a4b09ac192
Change-Id: I8b9b7d70abc47d672c68db65bc67d08beb7d41a7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/142089 Commit-Queue: Bob Nystrom <rnystrom@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
28 lines
1.1 KiB
Dart
28 lines
1.1 KiB
Dart
// Copyright (c) 2019, 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.
|
|
|
|
import 'package:expect/expect.dart';
|
|
|
|
void main() {
|
|
// Cast for variable.
|
|
dynamic nonInt = "string";
|
|
Expect.throwsTypeError(() => <int>[for (int i = nonInt; false;) 1]);
|
|
Expect.throwsTypeError(() => <int, int>{for (int i = nonInt; false;) 1: 1});
|
|
Expect.throwsTypeError(() => <int>{for (int i = nonInt; false;) 1});
|
|
|
|
// Cast for-in variable.
|
|
dynamic nonIterable = 3;
|
|
Expect.throwsTypeError(() => <int>[for (int i in nonIterable) 1]);
|
|
Expect.throwsTypeError(() => <int, int>{for (int i in nonIterable) 1: 1});
|
|
Expect.throwsTypeError(() => <int>{for (int i in nonIterable) 1});
|
|
|
|
// Wrong element type.
|
|
Expect.throwsTypeError(() => <int>[for (var i = 0; i < 1; i++) nonInt]);
|
|
Expect.throwsTypeError(
|
|
() => <int, int>{for (var i = 0; i < 1; i++) nonInt: 1});
|
|
Expect.throwsTypeError(
|
|
() => <int, int>{for (var i = 0; i < 1; i++) 1: nonInt});
|
|
Expect.throwsTypeError(() => <int>{for (var i = 0; i < 1; i++) nonInt});
|
|
}
|