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

InstanceMirror.newInstance will throw a NoSuchMethodError when the reflected class's constructor has optional parameters #15942

Closed
DartBot opened this issue Jan 7, 2014 · 6 comments
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js

Comments

@DartBot
Copy link

DartBot commented Jan 7, 2014

This issue was originally filed by mr...@gmail.com


What steps will reproduce the problem?

  1. Create a class who's constructor has optional parameters
  2. Get a ClassMirror for this class using reflectClass
  3. Call newInstance on the ClassMirror without specifying any positional arguments.

What is the expected output? What do you see instead?
I expect a valid InstanceMirror to be created, but instead I get a NoSuchMethodError.

What version of the product are you using? On what operating system?
Dart Editor version 1.1.0.dev_05_00 (DEV)
Dart SDK version 1.1.0-dev.5.0
Mac OS X 10.9.1

Please provide any additional information below.
Can be fixed currently by passing the correct amount of positional arguments, or by removing the optional parameter entirely from the constructor. Neither are acceptable.


Attachment:
test.dart (201 Bytes)

@DartBot
Copy link
Author

DartBot commented Jan 7, 2014

This comment was originally written by mrand0...@gmail.com


I should add that this works in native Dart, but does not when running through dart2js.

@sethladd
Copy link
Contributor

sethladd commented Jan 7, 2014

Added Area-VM, Triaged labels.

@iposva-google
Copy link
Contributor

Removed Area-VM label.
Added Area-Dart2JS label.

@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed priority-unassigned labels Feb 29, 2016
@jolleekin
Copy link

Any updates? It has been almost three years!

@floitschG
Copy link
Contributor

Can you provide an example?

I just tried to reproduce but couldn't trigger the bug.

Here is what I tried:

@MirrorsUsed(targets: const ["A"])
import 'dart:mirrors';

class A {
  A(y, {x}) {print("$x $y"); }
  A.named(y, [x]) {print("$x $y"); }
  A.named2([x = 499]) {print("$x"); }
  A.named3({x : 42}) {print("$x"); }
}

main() {
  var cm = reflectClass(A);
  print(cm.newInstance(const Symbol(""), [499]));
  print(cm.newInstance(const Symbol("named"), [499]));
  print(cm.newInstance(const Symbol("named2"), []));
  print(cm.newInstance(const Symbol("named3"), []));
}

Which prints:

null 499
InstanceMirror on Instance of 'A'
null 499
InstanceMirror on Instance of 'A'
499
InstanceMirror on Instance of 'A'
42
InstanceMirror on Instance of 'A'

@jolleekin
Copy link

Seems like this bug has been fixed. The following code used to fail but works now.

  var cm = reflectClass(List);
  var rm = cm.newInstance(const Symbol(''), []);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) web-dart2js
Projects
None yet
Development

No branches or pull requests

7 participants