mirror of
https://github.com/dart-lang/sdk
synced 2024-09-19 14:32:49 +00:00
2432ac4647
New scheme for checking function subtyping: 1) Generate an $isX predicate on objects that are statically known subtypes of a given function type 2) Generate a signature encoding the whole function type on objects when a runtime check is needed. A check succeeds if either 1) or 2) is true. If too many predicates are needed a signature is generated instead, and if a signature is needed, no predicates are generated. Maximum number of predicates is currently determined by the magic constant MAX_FUNCTION_TYPE_PREDICATES in emitter.dart. R=karlklose@google.com Committed: https://code.google.com/p/dart/source/detail?r=24286 Review URL: https://codereview.chromium.org//12334070 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@24309 260f80e4-7a28-3924-810f-c04153c831b5
43 lines
1.3 KiB
Dart
43 lines
1.3 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() {
|
|
Expect.isTrue(new C1() is Foo, 'new C1() is Foo');
|
|
Expect.isTrue(new C1() is Bar, 'new C1() is Bar');
|
|
Expect.isFalse(new C1() is Baz, 'new C1() is Baz');
|
|
Expect.isTrue(new C1() is Boz, 'new C1() is Boz');
|
|
|
|
Expect.isFalse(new C2() is Foo, 'new C2() is Foo');
|
|
Expect.isFalse(new C2() is Bar, 'new C2() is Bar');
|
|
Expect.isTrue(new C2() is Baz, 'new C2() is Baz');
|
|
Expect.isTrue(new C2() is Boz, 'new C2() is Boz');
|
|
|
|
Expect.isFalse(new C3() is Foo, 'new C3() is Foo');
|
|
Expect.isFalse(new C3() is Bar, 'new C3() is Bar');
|
|
Expect.isFalse(new C3() is Baz, 'new C3() is Baz');
|
|
Expect.isTrue(new C3() is Boz, 'new C3() is Boz');
|
|
}
|