f0a6330db0
This CL is the first in a series of CLs to change the handling of callable classes in Dart 2.0. For purposes of this description, a "callable class" is a class whose interface contains a `.call` method. In Dart 1.0, a callable class was considered to be a subtype of the `.call` method's function type. This allowed the user to create custom objects with similar behavior to closures, but with additional fields and methods. In Dart 2.0, a callable class is just an ordinary class, with no subtype relation to any particular function type. (Note however that it is still permissible for a class to declare that it "implements Function"). To reduce the amount of code broken by this change, a piece of syntactic sugar is being added: if an expression whose static type is a callable class appears where a function type is expected, an implicit tear-off of the `.call` method is inserted. Note that it is still possible at compile time to invoke an expression whose static type is a callable class, and it is still possible at runtime to invoke an expression whose runtime type is a callable class; in both cases, this is considered an implicit invocation of the class's `.call` method. This is unchanged from Dart 1.0 behavior. This CL introduces test cases for the new behavior, and implements the implicit tear-off of `.call` in the front end. Still to be implemented in future CLs: - Spec text needs to be written. - DDC/analyzer code needs to be written to perform implicit tear-offs of `.call`. - The subtyping algorithm in DDC, analyzer, VM, and dart2js needs to be changed so that callable classes are no longer considered subtypes of any particular function type. - A small corner case involving type parameters still needs to be addressed (see TODO in pkg/front_end/lib/src/fasta/type_inference/type_inferrer.dart). Fixes #32064. Change-Id: I6a86491047ae467a5e767cb3cc7cecb570b29308 Reviewed-on: https://dart-review.googlesource.com/40508 Commit-Queue: Paul Berry <paulberry@google.com> Reviewed-by: Kevin Millikin <kmillikin@google.com> Reviewed-by: Leaf Petersen <leafp@google.com> Reviewed-by: Erik Ernst <eernst@google.com>
Run Existing Tests ================== See the output of ../tools/test.py --help for how to run tests. See also https://code.google.com/p/dart/wiki/Building#Testing for detailed examples. Create New Tests ================ See comments above factory StandardTestSuite.forDirectory in ../tools/testing/dart/test_suite.dart for the default test directory layout. By default test-file names must end in "_test.dart", but some test suites, such as ./co19, subclass StandardTestSuite and override this default. See comments at the beginning of ../tools/testing/dart/multitest.dart for how to create tests that pass by failing with a known error. For example, ... int x = "not an int"; /// 01: static type warning ... as part of a test will only pass the "--compiler dart2analyzer" test if the assignment generates a static type warning.