sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Accessing the values of inherited fields via `DartObject` is difficult to figure out

Open bwilkerson opened this issue 1 year ago • 1 comments

In order to access the value of an inherited field by using the DartObject.getField method you're required to access the (super) field of the object (possibly multiple times).

While this allows access to shadowed fields, the magic name used to access the inherited fields isn't documented and is hard to guess.

At the very least we need to document the fact that inherited fields aren't directly accessible and how to access them.

We should also consider possible ways to improve the API. For example, we could consider changing getField to take both the name of the field and (maybe optionally) the name of the superclass in which look-up should begin. For most uses it would probably be fine to not provide the superclass name and to take the field defined by the lowest subclass.

@scheglov

bwilkerson avatar Feb 12 '24 19:02 bwilkerson

I'd consider adding a DartObject.superObject to wrap about that '(super)'

There's some value in it, considering it changes DartObject.type (at least I assume. I haven't actually checked)

rrousselGit avatar Feb 12 '24 19:02 rrousselGit