ironpython3
ironpython3 copied to clipboard
Extensible<T> fails on accessing static properties
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.
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;
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.