mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:56:57 +00:00
df9ca4c9f9
Change-Id: I1f46f28c220ba2a6d5c5e3dc4f2c3efd010c7a8a Reviewed-on: https://dart-review.googlesource.com/68664 Reviewed-by: Kevin Millikin <kmillikin@google.com> Commit-Queue: Erik Ernst <eernst@google.com>
56 lines
1.8 KiB
Dart
56 lines
1.8 KiB
Dart
// Copyright (c) 2011, 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";
|
|
|
|
// Checks that a method with an instantiated return type can override a method
|
|
// with a generic return type.
|
|
|
|
typedef V RemoveFunctionType<K, V>(K key);
|
|
|
|
class MapBase<K, V> {
|
|
K remove(K key) {
|
|
throw 'Must be implemented';
|
|
}
|
|
|
|
void tests() {
|
|
Expect.isTrue(this is MapBase<int, int>);
|
|
|
|
// `remove` takes an argument which is covariant-by-class, so
|
|
// the tear-off has dynamic type `int Function(Object)`.
|
|
|
|
Expect.isTrue(remove is RemoveFunctionType);
|
|
Expect.isTrue(remove is RemoveFunctionType<int, int>);
|
|
Expect.isTrue(remove is RemoveFunctionType<String, int>);
|
|
Expect.isTrue(remove is RemoveFunctionType<MapBase<int, int>, int>);
|
|
}
|
|
}
|
|
|
|
class MethodOverrideTest extends MapBase<String, String> {
|
|
String remove(String key) {
|
|
throw 'Must be implemented';
|
|
}
|
|
|
|
void tests() {
|
|
Expect.isTrue(this is MethodOverrideTest);
|
|
Expect.isTrue(this is MapBase<String, String>);
|
|
|
|
// `remove` takes an argument which is covariant-by-class because
|
|
// an overridden method does so, and hence the tear-off has dynamic
|
|
// type `String Function(Object)`; so does `super.remove`.
|
|
|
|
Expect.isTrue(remove is RemoveFunctionType);
|
|
Expect.isTrue(remove is RemoveFunctionType<String, String>);
|
|
Expect.isTrue(remove is! RemoveFunctionType<int, int>);
|
|
Expect.isTrue(super.remove is RemoveFunctionType);
|
|
Expect.isTrue(super.remove is RemoveFunctionType<String, String>);
|
|
Expect.isTrue(super.remove is! RemoveFunctionType<int, int>);
|
|
}
|
|
}
|
|
|
|
main() {
|
|
new MapBase<int, int>().tests();
|
|
new MethodOverrideTest().tests();
|
|
}
|