Considering the following code:
import 'dart:mirrors'; typedef T1 getterField<T1, T2>(T2); class A { String _name; String get name => _name; set name(String n) { print("setting name to " + n); _name = n; } static final getterField<String, A> nameField = ((A a) { return a.name; }); } void main() { A a = new A(); a.name = "Paul"; InstanceMirror m = reflect(A.nameField); print(m.toString()); // Warning given for the following line (as expected): // A value of type 'String' cannot be assigned to a variable // of type 'int' // num i = A.nameField(a); }
The output is:
setting name to Paul
ClosureMirror on 'Closure: (A) => dynamic'
However, as the comment in the code illustrates, the assignment to i
(that is also commented out) is statically shown as an error.
Am I missing something here? Why is the output not:
setting name to Paul
ClosureMirror on 'Closure: (A) => String'
Thanks
typedef T1 someTypedef<T1, T2>(T2);
someTypedef nf = A.nameField;
var cm = reflectClass(A);
List types = (cm.declarations[#nameField] as VariableMirror).type.typeArguments;
print(types);
You are reflecting on the value the field holds.
There could be more than one typedef a closure signature corresponds to.There is no 1:1 relation between closure and typedef like with instance and class as far as I know.
static final getterField<String, A> nameField = dynamic ((A a) { return a.name; });
static final getterField<String, A> nameField = _foo;static String _foo(A a) {return a.name;}
--
For other discussions, see https://groups.google.com/a/dartlang.org/
For HOWTO questions, visit http://stackoverflow.com/tags/dart
To file a bug report or feature request, go to http://www.dartbug.com/new
To unsubscribe from this group and stop receiving emails from it, send an email to misc+uns...@dartlang.org.