mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:36:59 +00:00
615be6451e
generic_instanceof ... getter_closure_execution_order_test. The main interesting one is generic_methods_type_expression_test. It was testing old Dart 1.0-specific behavior and needed a lot of changes. R=jmesserly@google.com Review-Url: https://codereview.chromium.org/3001803002 .
61 lines
1.6 KiB
Dart
61 lines
1.6 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.
|
|
|
|
import 'package:expect/expect.dart';
|
|
|
|
// Test runtime behavior of generic function typedefs:
|
|
//
|
|
// - use "is" and "as" on them.
|
|
// - get Type values from runtimeType.
|
|
// - pass type parameters from another generic type to them.
|
|
|
|
typedef A<T> = T Function(T x, T y);
|
|
typedef B = T Function<T>(T x, T y);
|
|
|
|
typedef C<K> = Map<K, V> Function<V>(K k, V v);
|
|
typedef D = Map<String, V> Function<V>(String k, V v);
|
|
|
|
class G<Y, Z> {
|
|
test() {
|
|
dynamic d = (Y x, Y y) => y;
|
|
Expect.isTrue(d is A<Y>);
|
|
Expect.equals(d is A<Z>, Y == Z);
|
|
|
|
Expect.isFalse(d is B);
|
|
Expect.throws(() => d as B);
|
|
|
|
d = (Y y, Z z) => <Y, Z>{};
|
|
Expect.isFalse(d is C<Y>);
|
|
|
|
d = <S>(Y y, S s) => <Y, S>{};
|
|
Expect.isTrue(d is C<Y>);
|
|
Expect.equals(d is C<Z>, Y == Z);
|
|
Expect.equals(d is D, Y == String);
|
|
}
|
|
}
|
|
|
|
main() {
|
|
dynamic d = (int x, int y) => x + y;
|
|
Expect.isTrue(d is A<int>);
|
|
Expect.equals((d as A<int>)(1, 2), 3);
|
|
|
|
Expect.isFalse(d is B);
|
|
Expect.throws(() => d as B);
|
|
|
|
d = <S>(S x, S y) => x is String ? x : y;
|
|
Expect.isFalse(d is A);
|
|
Expect.throws(() => d as A);
|
|
|
|
Expect.isTrue(d is B);
|
|
// TODO(jmesserly): Analyzer incorrectly rejects this form:
|
|
// Expect.equals((d as B)<int>(1, 2), 2);
|
|
B b = d;
|
|
Expect.equals(b<int>(1, 2), 2);
|
|
Expect.equals(b<String>('a', 'b'), 'a');
|
|
|
|
|
|
new G<int, String>().test();
|
|
new G<String, String>().test();
|
|
}
|