question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Question: Nullable Immutable Arrays

See original GitHub issue

First off, amazing project. 😃 We are using it for ExtendedXmlSerializer.

Secondly, finally ran into my first problem here after many (many!) times of “just working”.

I have the following class:

class Subject
{
    public Subject(ImmutableArray<int>? test)
    {
        Test = test;
    }

    public ImmutableArray<int>? Test { get; }
}

But when I do this:

new Subject(ImmutableArray.Create(1, 2, 3))
    .ShouldBeEquivalentTo(new Subject(ImmutableArray.Create(1, 2, 3)));

I get the following failure: Expected member Test to be {1, 2, 3}, but found {1, 2, 3}.

Looks like it has to do with being a nullable value type. If I make it non-nullable it works as expected. Any suggestions on what I could be doing wrong? Thank you in advance for any assistance!

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
dennisdoomencommented, Feb 28, 2018

If I change my Test property from a ImmutableArray? to a ImmutableArray it works just fine

I found the problem. Nullable properties referring to types implementing IEnumerable are not detected as such, after which FA will fall back on value semantics. And ImmutableArray implements Equals by comparing the underlying arrays by reference.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Type inference for generic method differs between nullable ...
I have been warned that the immutable array is boxed when used as an enumerable, which comes with a performance penalty. But I...
Read more >
Mutable and Immutable Arrays - Learn TypeScript
Mutable and Immutable Arrays. In this lesson, you will learn about two different syntaxes to define an array. We'll cover the following.
Read more >
Solved True or false? All elements of an array must be of
Question : True or false? All elements of an array must be of the same type. Strings are immutable. Arrays cannot contain string...
Read more >
Null safety | Kotlin Documentation
Kotlin's type system is aimed at eliminating the danger of null references, also known as The Billion Dollar Mistake.
Read more >
Member access operators and expressions
C# operators that you use to access type members or null-conditionally access type members. These operators include the dot operator - `.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found