Skip to content

Commit

Permalink
ensuring structs could be constructed using default ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
eirannejad committed Jul 25, 2023
1 parent 1729698 commit 108d038
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/runtime/Types/MethodObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ public virtual NewReference Invoke(BorrowedReference inst, BorrowedReference arg

public virtual NewReference Invoke(BorrowedReference target, BorrowedReference args, BorrowedReference kw, MethodBase? info)
{
// NOTE: do nothing on struct default ctor
// do nothing and return 'void' when runtime is attempting
// to call __init__ with no arguments on a struct.
// ManagedType.GetManagedObject(target) returns the instance
if (name == "__init__"
&& !type.Value.IsClass
&& Runtime.PyTuple_Size(args) == 0)
{
return new NewReference(Runtime.PyNone);
}

return binder.Invoke(target, args, kw, info, this.info);
}

Expand Down

0 comments on commit 108d038

Please sign in to comment.