You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
since the compiler (rightfully) emits CS0037, “Cannot convert null to 'long' because it is a non-nullable value type”. If one works around that by casting to object before testing:
the code compiles but results in the runtime exception:
CSnakes.Runtime.PythonInvocationException
Error converting Python object to int, check that the object was a Python int or that the value wasn't too large. See InnerException for details.
at CSnakes.Runtime.CPython.CPythonAPI.PyLong_AsLongLong(PyObject p) in A:\CSnakes\main\src\CSnakes.Runtime\CPython\Long.cs:line 26
The inner exception reads:
CSnakes.Runtime.PythonRuntimeException
'NoneType' object cannot be interpreted as an integer
Exception doesn't have a stacktrace
The same problem exists with input arguments that are typed as Optional of some type (when there's no default of None given).
Suppose the following Python function:
I would have expected the C# method to return a
long?
, but instead it's typed to return justlong
:This means that it's not possible to test for
null
statically, like so:since the compiler (rightfully) emits CS0037, “Cannot convert null to 'long' because it is a non-nullable value type”. If one works around that by casting to
object
before testing:the code compiles but results in the runtime exception:
The inner exception reads:
The same problem exists with input arguments that are typed as
Optional
of some type (when there's no default ofNone
given).It looks like the problem is with
TypeReflection.AsPredefinedType
, which simply looks at the type argument:CSnakes/src/CSnakes.SourceGeneration/Reflection/TypeReflection.cs
Line 33 in 048e011
The existing nullability support is predicated on the presence of
None
as the default argument inArgumentReflection.ArgumentSyntax
:CSnakes/src/CSnakes.SourceGeneration/Reflection/ArgumentReflection.cs
Lines 85 to 88 in 048e011
The fix would be to consider
Optional
in the type hint as opposed to requiring a default ofNone
. This is especially problematic for the return value.The text was updated successfully, but these errors were encountered: