Navigation Menu

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

Must dynamically construct a symbol to access a named constructor with mirrors #13248

Closed
nex3 opened this issue Sep 11, 2013 · 3 comments
Closed
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-mirrors type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@nex3
Copy link
Member

nex3 commented Sep 11, 2013

The [ClassMirror.constructors] map indexes named constructors with symbols like "Foo" and "Foo.named". This means that if you statically know the name of the constructor you want but not the name of the class itself, you need to dynamically construct a symbol to reflect on that constructor (e.g. new Symbol("${MirrorSystem.getName(mirror.simpleName)}.named")).

Contrast this with [ClassMirror.newInstance], which refers to constructors using symbols that don't include the class name.

@gbracha
Copy link
Contributor

gbracha commented Jan 14, 2014

I agree this seems broken.This now the case in the map returned by declarations. I don't think this agrees with the specification and I believe it should be fixed. Invocation and lookup must be consistent.

The simple name of a constructor should be the identifier without the class or the constant symbol for the empty string if it is a default constructor.

This will break existing uses, but I think we can still do that as we revise the mirror library to its final form.


cc @rmacnak-google.
Set owner to @gbracha.
Added Accepted label.

@DartBot
Copy link

DartBot commented Apr 25, 2014

This comment was originally written by @Andersmholmgren


Similarly you end up in the unfortunate state where you can look up a constructor but then not instantiate off it

import 'dart:mirrors';

class Foo {
  Foo.build();
}

main() {
  final cm = reflectClass(Foo);

  Symbol ctrName;

  cm.declarations.forEach((k, v) {
    if (v is MethodMirror && v.isConstructor) {
      ctrName = k;
    }
  });

  final i = cm.newInstance(ctrName, []);
}

@nex3 nex3 added Type-Defect area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-mirrors labels Apr 25, 2014
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed priority-unassigned labels Feb 29, 2016
@natebosch
Copy link
Member

Closing in favor of #16075 since ClassMirrors.constructors no longer exists and the linked issue covers ClassMirrors.declarations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. library-mirrors type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

5 participants