Files
sdk/pkg/dev_compiler/test/codegen/methods.dart
T
Leaf Petersen 8040611a79 This CL implements tagging of functions and methods with function types.
For every class, we now generate a setSignature call which attaches properties to the constructor recording the method signatures, the static function signatures, and the names of all of the static methods. This call also attaches a getter to every static method which returns the type of the function.  Methods are only decorated with runtime types when torn off.  At a tear-off, the type is looked up in the constructor, and then attached to the bound function.

Top level functions and statement level functions get annotated with their type immediately after their declaration.  We could consider moving all of the top level function annotations to the end of the file, but for now I've left it inline.

Closures (function expressions) get wrapped in calls to a dart.fn helper, with type information attached in one of various forms.  This is currently the least attractive part of this CL.  We may want to iterate on the syntax for this.

I've added some support for NSM checking to the dsend/dcall case as well.

We may wish to iterate on the syntax, and on the runtime representation of types, but this should move us forward from a functionality standpoint.

BUG=
R=jmesserly@google.com, vsm@google.com

Review URL: https://codereview.chromium.org/1138793002
2015-05-19 16:24:35 -07:00

59 lines
900 B
Dart

// Copyright (c) 2015, 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.
library methods;
class A {
int x() => 42;
int y(int a) {
return a;
}
int z([num b]) => b;
int zz([int b = 0]) => b;
int w(int a, {num b}) {
return a + b;
}
int ww(int a, {int b: 0}) {
return a + b;
}
int get a => x();
void set b(int b) {}
int _c = 3;
int get c => _c;
void set c(int c) {
_c = c;
}
}
class Bar {
call(x) => print('hello from $x');
}
class Foo {
final Bar bar = new Bar();
}
test() {
// looks like a method but is actually f.bar.call(...)
var f = new Foo();
f.bar("Bar's call method!");
// Tear-off
A a = new A();
var g = a.x;
// Dynamic Tear-off
dynamic aa = new A();
var h = aa.x;
}