support tear-offs for constructors #17907
Labels
area-language
Dart language related items (some items might be better tracked at github.com/dart-lang/language).
closed-duplicate
Closed in favor of an existing report
This issue was originally filed by bsles...@gmail.com
It would be convenient to convert a constructor to a function:
class Foo {
final int x;
final int y;
Foo.make(this.x, this.y);
}
final Function makeFoo = Foo.make;
main() {
makeFoo(1, 2);
}
The result is:
NoSuchMethodError: method not found: 'get:make'
Receiver: Type: class 'Foo'
Arguments: [...]
0 NoSuchMethodError._throwNew (dart:core-patch/errors_patch.dart:166)
1 makeFoo (file:///Users/skybrian/dart/bugtest/bin/tearoff.dart:7:26)
2 main (file:///Users/skybrian/dart/bugtest/bin/tearoff.dart:10:3)
3 _startIsolate.isolateStartHandler (dart:isolate-patch/isolate_patch.dart:216)
4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:115)
Workaround 1: write a function that calls the constructor. However, this can be tedious if the constructor takes a large number of optional arguments.
Workaround 2: perhaps use noSuchMethod and ClassMirror.newInstance?
The text was updated successfully, but these errors were encountered: