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

Extensible<T> fails on accessing static properties #1326

Open
BCSharp opened this issue Feb 24, 2022 · 2 comments
Open

Extensible<T> fails on accessing static properties #1326

BCSharp opened this issue Feb 24, 2022 · 2 comments

Comments

@BCSharp
Copy link
Member

BCSharp commented Feb 24, 2022

When accessing static properties of T through Extensible<T> (e.g. BigInteger.Zero), a type error is raised. Accessing instance properties (e.g. String.Length) or static fields (e.g. Int32.MaxValue) works fine.

Example:

import clr, System
clr.AddReference('System.Numerics')

bi = System.Numerics.BigInteger(42)
assert bi.IsEven     # OK
assert bi.Zero == 0  # OK

class mybig(System.Numerics.BigInteger): pass

ebi = mybig(42)
assert ebi.IsEven     # OK
assert ebi.Zero == 0  # TypeError: Zero() takes no arguments (0 given)

This issue is blocking #52.

@slozier
Copy link
Contributor

slozier commented Feb 25, 2022

Maybe more of a hack than a proper solution, but I'm thinking the following in ReflectedProperty.CallGetter would do the trick:

Debug.Assert(members.Length == 1);
if (members[0].IsStatic) instance = null;

@BCSharp
Copy link
Member Author

BCSharp commented Feb 25, 2022

Hmm... Seems that ReflectedProperty.MateGetExpresion may be missing the ExplicitCast expression casting from instance to the declaring type of the chosen getter. I've also noticed that while there are extensive tests in ./Test/interop/net/field and ./Test/interop/net/method, the equivalent tests for properties are missing. So there may be more things that are not quite working for properties. I think it is worth investigating deeper and write the missing tests but for now I'll take your workaround as I want to get the PR for #52 out the door. It will probably take a while to get reviewed, so in the meantime I can tie up some loose ends.

BCSharp added a commit to BCSharp/ironpython3 that referenced this issue Feb 25, 2022
slozier pushed a commit that referenced this issue Feb 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants