提交 e2cbbeec 编写于 作者: M Manish Vasani

Address feedback

上级 2c942ec4
......@@ -785,10 +785,11 @@ protected BoundCall MakeQueryInvocation(CSharpSyntaxNode node, BoundExpression r
protected BoundExpression MakeConstruction(CSharpSyntaxNode node, NamedTypeSymbol toCreate, ImmutableArray<BoundExpression> args, DiagnosticBag diagnostics)
{
Debug.Assert(toCreate.IsAnonymousType);
var result = new BoundAnonymousObjectCreationExpression(node, toCreate.InstanceConstructors[0], args, ImmutableArray<BoundAnonymousPropertyDeclaration>.Empty, toCreate);
AnalyzedArguments analyzedArguments = AnalyzedArguments.GetInstance();
analyzedArguments.Arguments.AddRange(args);
var result = BindClassCreationExpression(node, toCreate.Name, node, toCreate, analyzedArguments, diagnostics);
result.WasCompilerGenerated = true;
analyzedArguments.Free();
return result;
}
}
......
......@@ -530,6 +530,18 @@ private IOperation CreateBoundObjectCreationExpressionOperation(BoundObjectCreat
{
return CreateInvalidExpressionForHasArgumentsExpression(null, boundObjectCreationExpression.Arguments, boundObjectCreationExpression.InitializerExpressionOpt, syntax, type, constantValue, isImplicit);
}
else if (boundObjectCreationExpression.Type.IsAnonymousType)
{
// Workaround for https://github.com/dotnet/roslyn/issues/28157
Debug.Assert(isImplicit);
var memberInitializers = new Lazy<ImmutableArray<IOperation>>(() => GetAnonymousObjectCreationInitializers(
boundObjectCreationExpression.Arguments,
declarations: ImmutableArray<BoundAnonymousPropertyDeclaration>.Empty,
syntax,
type,
isImplicit));
return new LazyAnonymousObjectCreationExpression(memberInitializers, _semanticModel, syntax, type, constantValue, isImplicit);
}
Lazy<IObjectOrCollectionInitializerOperation> initializer = new Lazy<IObjectOrCollectionInitializerOperation>(() => (IObjectOrCollectionInitializerOperation)Create(boundObjectCreationExpression.InitializerExpressionOpt));
Lazy<ImmutableArray<IArgumentOperation>> arguments = new Lazy<ImmutableArray<IArgumentOperation>>(() =>
......
......@@ -205,15 +205,25 @@ private IInvalidOperation CreateInvalidExpressionForHasArgumentsExpression(Bound
}
private ImmutableArray<IOperation> GetAnonymousObjectCreationInitializers(BoundAnonymousObjectCreationExpression expression)
{
return GetAnonymousObjectCreationInitializers(expression.Arguments, expression.Declarations, expression.Syntax, expression.Type, expression.WasCompilerGenerated);
}
private ImmutableArray<IOperation> GetAnonymousObjectCreationInitializers(
ImmutableArray<BoundExpression> arguments,
ImmutableArray<BoundAnonymousPropertyDeclaration> declarations,
SyntaxNode syntax,
ITypeSymbol type,
bool isImplicit)
{
// For error cases and non-assignment initializers, the binder generates only the argument.
Debug.Assert(expression.Arguments.Length >= expression.Declarations.Length);
Debug.Assert(arguments.Length >= declarations.Length);
var builder = ArrayBuilder<IOperation>.GetInstance(expression.Arguments.Length);
var builder = ArrayBuilder<IOperation>.GetInstance(arguments.Length);
var currentDeclarationIndex = 0;
for (int i = 0; i < expression.Arguments.Length; i++)
for (int i = 0; i < arguments.Length; i++)
{
IOperation value = Create(expression.Arguments[i]);
IOperation value = Create(arguments[i]);
IOperation target;
bool isImplicitAssignment;
......@@ -222,15 +232,15 @@ private ImmutableArray<IOperation> GetAnonymousObjectCreationInitializers(BoundA
var instance = new InstanceReferenceExpression(
referenceKind: InstanceReferenceKind.ImplicitReceiver,
semanticModel: _semanticModel,
syntax: expression.Syntax,
type: expression.Type,
syntax: syntax,
type: type,
constantValue: default,
isImplicit: true);
// Find matching declaration for the current argument.
IPropertySymbol property = AnonymousTypeManager.GetAnonymousTypeProperty((NamedTypeSymbol)expression.Type, i);
if (currentDeclarationIndex >= expression.Declarations.Length ||
(object)property != expression.Declarations[currentDeclarationIndex].Property)
IPropertySymbol property = AnonymousTypeManager.GetAnonymousTypeProperty((NamedTypeSymbol)type, i);
if (currentDeclarationIndex >= declarations.Length ||
(object)property != declarations[currentDeclarationIndex].Property)
{
// No matching declaration, synthesize a property reference to be assigned.
target = new PropertyReferenceExpression(
......@@ -246,19 +256,19 @@ private ImmutableArray<IOperation> GetAnonymousObjectCreationInitializers(BoundA
}
else
{
target = CreateBoundAnonymousPropertyDeclarationOperation(expression.Declarations[currentDeclarationIndex++], instance);
isImplicitAssignment = expression.WasCompilerGenerated;
target = CreateBoundAnonymousPropertyDeclarationOperation(declarations[currentDeclarationIndex++], instance);
isImplicitAssignment = isImplicit;
}
SyntaxNode syntax = value.Syntax?.Parent ?? expression.Syntax;
ITypeSymbol type = target.Type;
var assignmentSyntax = value.Syntax?.Parent ?? syntax;
ITypeSymbol assignmentType = target.Type;
Optional<object> constantValue = value.ConstantValue;
bool isRef = false;
var assignment = new SimpleAssignmentExpression(target, isRef, value, _semanticModel, syntax, type, constantValue, isImplicitAssignment);
var assignment = new SimpleAssignmentExpression(target, isRef, value, _semanticModel, assignmentSyntax, assignmentType, constantValue, isImplicitAssignment);
builder.Add(assignment);
}
Debug.Assert(currentDeclarationIndex == expression.Declarations.Length);
Debug.Assert(currentDeclarationIndex == declarations.Length);
return builder.ToImmutableAndFree();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册