Skip to content

Collection-typed public fields throw: FieldInfo is cast to ICollection instead of its value #53

Closed

Description

@HowardvanRooijen

Summary

Theorem.cs:439:

int existingLength = parameter switch
{
    PropertyInfo info => ((ICollection)info.GetValue(destinationObject, null)!).Count,
    FieldInfo info1 => ((ICollection)info1).Count,   // <-- casts the FieldInfo itself
    _ => 0
};

The FieldInfo itself is cast to ICollection, rather than the value it holds. The
PropertyInfo branch immediately above does it correctly.

Impact

Any environment type with a public field of collection type throws InvalidCastException.
Collection-typed properties work.

Suggested fix

FieldInfo info1 => ((ICollection)info1.GetValue(destinationObject)!).Count,

Note the fix turns an exception into a newly-live code path that then runs the whole array
materialisation block, which is itself untested — worth its own PR with tests.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions