Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust closure initialization for primary constructor #66340

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using Microsoft.CodeAnalysis.CodeGen;
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
Expand Down Expand Up @@ -772,7 +773,15 @@ private void InitVariableProxy(SyntaxNode syntax, Symbol symbol, LocalSymbol fra
var assignToProxy = new BoundAssignmentOperator(syntax, left, value, value.Type);
if (_currentMethod.MethodKind == MethodKind.Constructor &&
symbol == _currentMethod.ThisParameter &&
!_seenBaseCall)
!_seenBaseCall &&
// Primary constructor doesn't have any user code after base constructor initializer.
// Therefore, if we detected a proxy for 'this', it must be used to refer in a lambda
// to a constructor parameter captured into the containing type state.
// That lambda could be executed before the base constructor initializer, or by
// the base constructor initializer. That is why we cannot defer the proxy
// initialization until after the base constructor initializer is executed.
// Even though that is going to be an unverifiable IL.
_currentMethod is not SynthesizedPrimaryConstructor)
{
// Containing method is a constructor
// Initialization statement for the "this" proxy must be inserted
Expand All @@ -782,6 +791,9 @@ private void InitVariableProxy(SyntaxNode syntax, Symbol symbol, LocalSymbol fra
}
else
{
Debug.Assert(_currentMethod is not SynthesizedPrimaryConstructor primaryConstructor ||
symbol != _currentMethod.ThisParameter ||
primaryConstructor.GetCapturedParameters().Any());
prologue.Add(assignToProxy);
}
}
Expand Down
Loading