Moved synthetic receiver for property initializers to use the correct type in C#.

上级 1f6ae4ab
......@@ -4020,6 +4020,7 @@ private BoundExpression MakeBadExpressionForObjectCreation(ObjectCreationExpress
expanded,
argsToParamsOpt,
resultKind,
implicitReceiver.Type,
binderOpt: this,
type: boundMember.Type,
hasErrors: hasErrors);
......
......@@ -1322,6 +1322,7 @@
<Field Name="Expanded" Type="bool"/>
<Field Name="ArgsToParamsOpt" Type="ImmutableArray&lt;int&gt;" Null="allow"/>
<Field Name="ResultKind" PropertyOverrides="true" Type="LookupResultKind"/>
<Field Name="InstanceSymbol" Type="TypeSymbol" Null="disallow"/>
<!-- BinderOpt is a temporary solution for IOperation implementation and should probably be removed in the future -->
<!-- Tracked by https://github.com/dotnet/roslyn/issues/20787 -->
......
......@@ -4765,11 +4765,12 @@ public BoundObjectInitializerExpression Update(ImmutableArray<BoundExpression> i
internal sealed partial class BoundObjectInitializerMember : BoundExpression
{
public BoundObjectInitializerMember(SyntaxNode syntax, Symbol memberSymbol, ImmutableArray<BoundExpression> arguments, ImmutableArray<string> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, bool expanded, ImmutableArray<int> argsToParamsOpt, LookupResultKind resultKind, Binder binderOpt, TypeSymbol type, bool hasErrors = false)
public BoundObjectInitializerMember(SyntaxNode syntax, Symbol memberSymbol, ImmutableArray<BoundExpression> arguments, ImmutableArray<string> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, bool expanded, ImmutableArray<int> argsToParamsOpt, LookupResultKind resultKind, TypeSymbol instanceSymbol, Binder binderOpt, TypeSymbol type, bool hasErrors = false)
: base(BoundKind.ObjectInitializerMember, syntax, type, hasErrors || arguments.HasErrors())
{
Debug.Assert(!arguments.IsDefault, "Field 'arguments' cannot be null (use Null=\"allow\" in BoundNodes.xml to remove this check)");
Debug.Assert(instanceSymbol != null, "Field 'instanceSymbol' cannot be null (use Null=\"allow\" in BoundNodes.xml to remove this check)");
Debug.Assert(type != null, "Field 'type' cannot be null (use Null=\"allow\" in BoundNodes.xml to remove this check)");
this.MemberSymbol = memberSymbol;
......@@ -4779,6 +4780,7 @@ public BoundObjectInitializerMember(SyntaxNode syntax, Symbol memberSymbol, Immu
this.Expanded = expanded;
this.ArgsToParamsOpt = argsToParamsOpt;
this._ResultKind = resultKind;
this.InstanceSymbol = instanceSymbol;
this.BinderOpt = binderOpt;
}
......@@ -4798,6 +4800,8 @@ public BoundObjectInitializerMember(SyntaxNode syntax, Symbol memberSymbol, Immu
private readonly LookupResultKind _ResultKind;
public override LookupResultKind ResultKind { get { return _ResultKind;} }
public TypeSymbol InstanceSymbol { get; }
public Binder BinderOpt { get; }
public override BoundNode Accept(BoundTreeVisitor visitor)
......@@ -4805,11 +4809,11 @@ public override BoundNode Accept(BoundTreeVisitor visitor)
return visitor.VisitObjectInitializerMember(this);
}
public BoundObjectInitializerMember Update(Symbol memberSymbol, ImmutableArray<BoundExpression> arguments, ImmutableArray<string> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, bool expanded, ImmutableArray<int> argsToParamsOpt, LookupResultKind resultKind, Binder binderOpt, TypeSymbol type)
public BoundObjectInitializerMember Update(Symbol memberSymbol, ImmutableArray<BoundExpression> arguments, ImmutableArray<string> argumentNamesOpt, ImmutableArray<RefKind> argumentRefKindsOpt, bool expanded, ImmutableArray<int> argsToParamsOpt, LookupResultKind resultKind, TypeSymbol instanceSymbol, Binder binderOpt, TypeSymbol type)
{
if (memberSymbol != this.MemberSymbol || arguments != this.Arguments || argumentNamesOpt != this.ArgumentNamesOpt || argumentRefKindsOpt != this.ArgumentRefKindsOpt || expanded != this.Expanded || argsToParamsOpt != this.ArgsToParamsOpt || resultKind != this.ResultKind || binderOpt != this.BinderOpt || type != this.Type)
if (memberSymbol != this.MemberSymbol || arguments != this.Arguments || argumentNamesOpt != this.ArgumentNamesOpt || argumentRefKindsOpt != this.ArgumentRefKindsOpt || expanded != this.Expanded || argsToParamsOpt != this.ArgsToParamsOpt || resultKind != this.ResultKind || instanceSymbol != this.InstanceSymbol || binderOpt != this.BinderOpt || type != this.Type)
{
var result = new BoundObjectInitializerMember(this.Syntax, memberSymbol, arguments, argumentNamesOpt, argumentRefKindsOpt, expanded, argsToParamsOpt, resultKind, binderOpt, type, this.HasErrors);
var result = new BoundObjectInitializerMember(this.Syntax, memberSymbol, arguments, argumentNamesOpt, argumentRefKindsOpt, expanded, argsToParamsOpt, resultKind, instanceSymbol, binderOpt, type, this.HasErrors);
result.WasCompilerGenerated = this.WasCompilerGenerated;
return result;
}
......@@ -9044,8 +9048,9 @@ public override BoundNode VisitObjectInitializerExpression(BoundObjectInitialize
public override BoundNode VisitObjectInitializerMember(BoundObjectInitializerMember node)
{
ImmutableArray<BoundExpression> arguments = (ImmutableArray<BoundExpression>)this.VisitList(node.Arguments);
TypeSymbol instanceSymbol = this.VisitType(node.InstanceSymbol);
TypeSymbol type = this.VisitType(node.Type);
return node.Update(node.MemberSymbol, arguments, node.ArgumentNamesOpt, node.ArgumentRefKindsOpt, node.Expanded, node.ArgsToParamsOpt, node.ResultKind, node.BinderOpt, type);
return node.Update(node.MemberSymbol, arguments, node.ArgumentNamesOpt, node.ArgumentRefKindsOpt, node.Expanded, node.ArgsToParamsOpt, node.ResultKind, instanceSymbol, node.BinderOpt, type);
}
public override BoundNode VisitDynamicObjectInitializerMember(BoundDynamicObjectInitializerMember node)
{
......@@ -10449,6 +10454,7 @@ public override TreeDumperNode VisitObjectInitializerMember(BoundObjectInitializ
new TreeDumperNode("expanded", node.Expanded, null),
new TreeDumperNode("argsToParamsOpt", node.ArgsToParamsOpt, null),
new TreeDumperNode("resultKind", node.ResultKind, null),
new TreeDumperNode("instanceSymbol", node.InstanceSymbol, null),
new TreeDumperNode("binderOpt", node.BinderOpt, null),
new TreeDumperNode("type", node.Type, null)
}
......
......@@ -239,6 +239,7 @@ private BoundExpression MakeCollectionInitializer(BoundExpression rewrittenRecei
memberInit.Expanded,
memberInit.ArgsToParamsOpt,
memberInit.ResultKind,
memberInit.InstanceSymbol,
memberInit.BinderOpt,
memberInit.Type);
}
......
......@@ -633,7 +633,7 @@ public override BoundNode VisitObjectInitializerMember(BoundObjectInitializerMem
break;
}
return node.Update(member, arguments, node.ArgumentNamesOpt, node.ArgumentRefKindsOpt, node.Expanded, node.ArgsToParamsOpt, node.ResultKind, node.BinderOpt, type);
return node.Update(member, arguments, node.ArgumentNamesOpt, node.ArgumentRefKindsOpt, node.Expanded, node.ArgsToParamsOpt, node.ResultKind, node.InstanceSymbol, node.BinderOpt, type);
}
private static bool BaseReferenceInReceiverWasRewritten(BoundExpression originalReceiver, BoundExpression rewrittenReceiver)
......
......@@ -535,7 +535,7 @@ private IMemberReferenceExpression CreateBoundObjectInitializerMemberOperation(B
Lazy<IOperation> instance = new Lazy<IOperation>(() => new InstanceReferenceExpression(
semanticModel: _semanticModel,
syntax: boundObjectInitializerMember.Syntax,
type: boundObjectInitializerMember.MemberSymbol.ContainingType,
type: boundObjectInitializerMember.InstanceSymbol,
constantValue: default(Optional<object>),
isImplicit: boundObjectInitializerMember.WasCompilerGenerated));
......
......@@ -10,7 +10,7 @@ public partial class IOperationTests : SemanticModelTestBase
{
[CompilerTrait(CompilerFeature.IOperation)]
[Fact]
public void IPropertyReferenceExpression_PropertyReferenceInDerivedTypeUsesBaseTypeAsInstanceType()
public void IPropertyReferenceExpression_PropertyReferenceInDerivedTypeUsesDerivedTypeAsInstanceType()
{
string source = @"
class C
......@@ -33,7 +33,7 @@ class C2 : C1
string expectedOperationTree = @"
ISimpleAssignmentExpression (OperationKind.SimpleAssignmentExpression, Type: System.Int32) (Syntax: 'P1 = 1')
Left: IPropertyReferenceExpression: System.Int32 C1.P1 { get; set; } (OperationKind.PropertyReferenceExpression, Type: System.Int32) (Syntax: 'P1')
Instance Receiver: IInstanceReferenceExpression (OperationKind.InstanceReferenceExpression, Type: C1) (Syntax: 'P1')
Instance Receiver: IInstanceReferenceExpression (OperationKind.InstanceReferenceExpression, Type: C2) (Syntax: 'P1')
Right: ILiteralExpression (OperationKind.LiteralExpression, Type: System.Int32, Constant: 1) (Syntax: '1')
";
var expectedDiagnostics = DiagnosticDescription.None;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册