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

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