Bug: Empty Array is projected as null instead of an array of length 0
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 665
- Forks
- 134
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 32
Description
Description
Consider the idl:
String[] GetItems();
If the implementation of this function returns an empty array, the CsWinRT projection will return null. But it is expected to return a non-null empty array.
The downside of empty arrays being projected as null is that it forces the consumer to write unnatural code:
string[] items = thing.GetItems();
if (items != null)
{
foreach (var item in items)
{
Console.WriteLine(item);
}
}
instead of the more idiomatic:
foreach (var item in thing.GetItems())
{
Console.WriteLine(item);
}
@oldnewthing as FYI.
Steps To Reproduce
See description.
Expected Behavior
See description.
Version Info
2.2.0
Additional Context
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the String[] GetItems() case described in the issue with an implementation that returns an empty array, then trace the CsWinRT projection path that produces the C# result. Done means an empty projected result is non-null, has length 0, and supports direct enumeration without a null check.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- desktop
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100