Skip to content

Unexpected redundant reference during C# lowering #71948

Answered by CyrusNajmabadi
dariomrk asked this question in Q&A
Discussion options

You must be logged in to vote

This is by design. The language says that this assigns to a temp and then finally assigns the temp to the final location.

Is this reflective of the actual compiler output,

THis is the actual compiler output.

Could someone clarify the rationale behind creating this additional reference in the lowered code (given that this is actual compiler output)?

Sure. Imagine you had the following:

private HashSet<string> set;

void Initialize()
{
    set = new HashSet<string> { "a", "b", GetValue() };
}

string GetValue() => throw new NotImplementedException();

We do not want 'set' to be in an intermediate state just because GetValue() failed. We want it to be totally initialized, or not at all.

S…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by dariomrk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants