-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Fix IEventAssignmentExpression #20960
Changes from 8 commits
5aca5d7
6a1c967
a9117b7
d1fe56b
0e0e4ef
d500d52
f8bf025
601987b
ab14b77
3fbbebd
0f17f9e
4485c1d
7c0283c
f995261
08016e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
using System.Linq; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
using Microsoft.CodeAnalysis.CSharp.Symbols; | ||
using Microsoft.CodeAnalysis.CSharp.Syntax; | ||
using Microsoft.CodeAnalysis.PooledObjects; | ||
using Roslyn.Utilities; | ||
|
||
|
@@ -355,14 +356,26 @@ private IEventReferenceExpression CreateBoundEventAccessOperation(BoundEventAcce | |
|
||
private IEventAssignmentExpression CreateBoundEventAssignmentOperatorOperation(BoundEventAssignmentOperator boundEventAssignmentOperator) | ||
{ | ||
IEventSymbol @event = boundEventAssignmentOperator.Event; | ||
Lazy<IOperation> eventInstance = new Lazy<IOperation>(() => Create(boundEventAssignmentOperator.Event.IsStatic ? null : boundEventAssignmentOperator.ReceiverOpt)); | ||
SyntaxNode syntax = boundEventAssignmentOperator.Syntax; | ||
Lazy<IEventReferenceExpression> eventReference = new Lazy<IEventReferenceExpression>(() => | ||
{ | ||
// BoundEventAssignmentOperator doesn't hold on to BoundEventAccess provided during binding. | ||
// Based on the implementation of those two bound node types, the following data can be retrieved w/o changing BoundEventAssignmentOperator: | ||
// 1. the type of BoundEventAccess is the type of the event symbol. | ||
// 2. the constant value of BoundEventAccess is always null. | ||
// 3. the syntax of the boundEventAssignmentOperator is always AssignmentExpressionSyntax, so the syntax for the event reference would be the LHS of the assignment. | ||
IEventSymbol @event = boundEventAssignmentOperator.Event; | ||
Lazy<IOperation> instance = new Lazy<IOperation>(() => Create(boundEventAssignmentOperator.Event.IsStatic ? null : boundEventAssignmentOperator.ReceiverOpt)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the conditional expression here, i.e. is there a case where event is static but ReceiverOpt is non-null? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, will fix. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, it seems the conditional is necessary, since the receiver will not be null for static event reference: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should include the receiver in the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point. I have made the change for both C# and VB (and I noticed in test that adding handler to static event through an instance is not an error in VB. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I just mentioned offline, making this change causes us to return a Meanwhile, I 'm gonna revert this change (but keep those tests) to make the behavior consistent with other related operations, e.g.: Is this OK? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, we should have consistent behavior for related operations. It sounds reasonable to revert the change for now while we discuss the overall approach. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. By the way, there's already an issue tracking the |
||
SyntaxNode eventAccessSyntax = ((AssignmentExpressionSyntax)syntax).Left; | ||
|
||
return new LazyEventReferenceExpression(@event, instance, @event, eventAccessSyntax, @event.Type, ConvertToOptional(null)); | ||
}); | ||
|
||
Lazy<IOperation> handlerValue = new Lazy<IOperation>(() => Create(boundEventAssignmentOperator.Argument)); | ||
bool adds = boundEventAssignmentOperator.IsAddition; | ||
SyntaxNode syntax = boundEventAssignmentOperator.Syntax; | ||
ITypeSymbol type = boundEventAssignmentOperator.Type; | ||
Optional<object> constantValue = ConvertToOptional(boundEventAssignmentOperator.ConstantValue); | ||
return new LazyEventAssignmentExpression(@event, eventInstance, handlerValue, adds, syntax, type, constantValue); | ||
return new LazyEventAssignmentExpression(eventReference, handlerValue, adds, syntax, type, constantValue); | ||
} | ||
|
||
private IParameterReferenceExpression CreateBoundParameterOperation(BoundParameter boundParameter) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you refactor this into a separate method
CreateBoundEventReferenceExpressionOperation
?