Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support tear-offs for constructors #17907

Closed
DartBot opened this issue Mar 31, 2014 · 3 comments
Closed

support tear-offs for constructors #17907

DartBot opened this issue Mar 31, 2014 · 3 comments
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

Comments

@DartBot
Copy link

DartBot commented Mar 31, 2014

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?

@dgrove
Copy link
Contributor

dgrove commented Mar 31, 2014

Added Area-Language, Triaged labels.

@DartBot
Copy link
Author

DartBot commented Mar 31, 2014

This comment was originally written by @seaneagan


dupe of issue #10659

@gbracha
Copy link
Contributor

gbracha commented Aug 26, 2014

Added Duplicate label.
Marked as being merged into #10659.

@DartBot DartBot added Type-Defect 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 labels Aug 26, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

4 participants