mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 03:47:13 +00:00
bed5debbeb
Fixes #32156 Fixes #32157 Fixes #32426 This also fixes `implements Function` so it has no effect in Dart 2 (it is ignored for the purposes of subtyping.) Change-Id: Ibec9c77cd516b8b97fef68a579998598d0acf8c6 Reviewed-on: https://dart-review.googlesource.com/45141 Commit-Queue: Jenny Messerly <jmesserly@google.com> Reviewed-by: Paul Berry <paulberry@google.com> Reviewed-by: Vijay Menon <vsm@google.com>
61 lines
1.8 KiB
Dart
61 lines
1.8 KiB
Dart
// Copyright (c) 2013, 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.
|
|
// Dart test program for constructors and initializers.
|
|
|
|
// Check function subtyping for classes with call functions.
|
|
|
|
import 'package:expect/expect.dart';
|
|
|
|
typedef void Foo(bool a, [String b]);
|
|
typedef void Bar(bool a, [String b]);
|
|
typedef void Baz(bool a, {String b});
|
|
typedef void Boz(bool a);
|
|
|
|
class C1 {
|
|
void call(bool a, [String b]) {}
|
|
}
|
|
|
|
class C2 {
|
|
void call(bool a, {String b}) {}
|
|
}
|
|
|
|
class C3 {
|
|
void call(bool a, {int b}) {}
|
|
}
|
|
|
|
main() {
|
|
Function c1 = new C1(); // implicit tearoff of `call`
|
|
Expect.isTrue(c1 is Foo, 'c1 is Foo');
|
|
Expect.isTrue(c1 is Bar, 'c1 is Bar');
|
|
Expect.isFalse(c1 is Baz, 'c1 is Baz');
|
|
Expect.isTrue(c1 is Boz, 'c1 is Boz');
|
|
Expect.isFalse(c1 is C1, 'c1 is C1');
|
|
|
|
Function c2 = new C2(); // implicit tearoff of `call`
|
|
Expect.isFalse(c2 is Foo, 'c2 is Foo');
|
|
Expect.isFalse(c2 is Bar, 'c2 is Bar');
|
|
Expect.isTrue(c2 is Baz, 'c2 is Baz');
|
|
Expect.isTrue(c2 is Boz, 'c2 is Boz');
|
|
Expect.isFalse(c2 is C2, 'c2 is C2');
|
|
|
|
Function c3 = new C3(); // implicit tearoff of `call`
|
|
Expect.isFalse(c3 is Foo, 'c3 is Foo');
|
|
Expect.isFalse(c3 is Bar, 'c3 is Bar');
|
|
Expect.isFalse(c3 is Baz, 'c3 is Baz');
|
|
Expect.isTrue(c3 is Boz, 'c3 is Boz');
|
|
Expect.isFalse(c3 is C3, 'c3 is C3');
|
|
|
|
expectIsNotFunction(new C1());
|
|
expectIsNotFunction(new C2());
|
|
expectIsNotFunction(new C3());
|
|
}
|
|
|
|
expectIsNotFunction(Object obj) {
|
|
Expect.isFalse(obj is Function, '$obj should not be a Function');
|
|
Expect.isFalse(obj is Foo, '$obj should not be a Foo');
|
|
Expect.isFalse(obj is Bar, '$obj should not be a Bar');
|
|
Expect.isFalse(obj is Baz, '$obj should not be a Baz');
|
|
Expect.isFalse(obj is Boz, '$obj should not be a Boz');
|
|
}
|