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

Unexpected behavior of InstanceMirror.setField / invoke when invoking a setter. #13083

Closed
fsc8000 opened this issue Sep 5, 2013 · 3 comments
Closed
Labels
area-core-library SDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries. closed-not-planned Closed as we don't intend to take action on the reported issue library-mirrors type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@fsc8000
Copy link
Contributor

fsc8000 commented Sep 5, 2013

The attached program generates a NoSuchMethodError instead of invoking the setter g. This is the same on the Dart VM and in dart2js:

Symbol("g=")
Unhandled exception:
Class 'A' has no instance setter 'g=='.

NoSuchMethodError : method not found: 'g=='
Receiver: Instance of 'A'

Replacing setField with invoke does not help. Instead I get:

Symbol("g=")
Unhandled exception:
Class 'A' has no instance method 'g='.

NoSuchMethodError : method not found: 'g='
Receiver: Instance of 'A'
Arguments: [42]


Attachment:
invoc.dart (465 Bytes)

@peter-ahe-google
Copy link
Contributor

I suggest that

reflect(o).invoke(const Symbol('x='), [a])

becomes equivalent to:

reflect(o).setField(const Symbol('x'), a)


Set owner to @gbracha.
Added Library-Mirrors label.

@gbracha
Copy link
Contributor

gbracha commented Sep 9, 2013

Yes, I think that would be fine.


Added Accepted label.

@DartBot
Copy link

DartBot commented Jan 2, 2014

This comment was originally written by diego.rocha...@gmail.com


reflect(o).invoke(const Symbol('x='), [a])
does not work as of Dart SDK version 1.1.0-dev.4.0 .

An ugly workaround is to use MirrorSystem.getName and MirrorSystem.getSymbol:
var im = reflect(o);
var name = MirrorSystem.getName(x);
name = name.substring(0, name.length - 1);
im.setField(MirrorSystem.getSymbol(name), 42);

The updated program with the workaround is attached.


Attachment:
invokeSetter.dart (700 Bytes)

@fsc8000 fsc8000 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 Jan 2, 2014
@kevmoo kevmoo added type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) and removed priority-unassigned labels Feb 29, 2016
@a-siva a-siva added closed-as-intended Closed as the reported issue is expected behavior closed-not-planned Closed as we don't intend to take action on the reported issue and removed closed-as-intended Closed as the reported issue is expected behavior labels Aug 5, 2022
@a-siva a-siva closed this as completed Aug 5, 2022
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. closed-not-planned Closed as we don't intend to take action on the reported issue library-mirrors type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants