// 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 key); class MapBase implements Map { K remove(K key) { throw 'Must be implemented'; } void Tests() { Expect.isTrue(this is MapBase); Expect.isTrue(remove is RemoveFunctionType); Expect.isTrue(remove is RemoveFunctionType); Expect.isTrue(remove is! RemoveFunctionType); Expect.isTrue(remove is! RemoveFunctionType, int>); } } class MethodOverrideTest extends MapBase { String remove(String key) { throw 'Must be implemented'; } void Tests() { Expect.isTrue(this is MethodOverrideTest); Expect.isTrue(this is MapBase); Expect.isTrue(remove is RemoveFunctionType); Expect.isTrue(remove is RemoveFunctionType); Expect.isTrue(remove is! RemoveFunctionType); Expect.isTrue(super.remove is RemoveFunctionType); Expect.isTrue(super.remove is RemoveFunctionType); Expect.isTrue(super.remove is! RemoveFunctionType); } } main() { // Since method overriding is only checked statically, explicitly check // the subtyping relation using a function type alias. var x = new MethodOverrideTest(); Expect.isTrue(x.remove is RemoveFunctionType); // Perform a few more tests. x.Tests(); var m = new MapBase(); Expect.isTrue(m.remove is RemoveFunctionType); // Perform a few more tests. m.Tests(); }