-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Handle unspecified anonymous type property in VisualBasicOperationFactory #74091
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next
Next commit
Handle unspecified anonymous type property in VisualBasicOperationFac…
…tory
- Loading branch information
commit 6723d453491d707e48efcc35341c0a4d21e9d432
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1821,5 +1821,189 @@ Block[B3] - Exit | |
|
||
VerifyFlowGraphAndDiagnosticsForTest(Of MethodBlockSyntax)(source, expectedFlowGraph, expectedDiagnostics) | ||
End Sub | ||
|
||
<Fact()> | ||
Public Sub ObjectCreation_WithMissingMember() | ||
Dim source = <![CDATA[ | ||
Module Program | ||
Sub Main() 'BIND:"Sub Main()" | ||
Dim item = New C() With {.} | ||
End Sub | ||
End Module | ||
Class C | ||
End Class | ||
]]>.Value | ||
Dim expectedDiagnostics = <![CDATA[ | ||
BC30201: Expression expected. | ||
Dim item = New C() With {.} | ||
~ | ||
BC30203: Identifier expected. | ||
Dim item = New C() With {.} | ||
~ | ||
BC30984: '=' expected (object initializer). | ||
Dim item = New C() With {.} | ||
~ | ||
]]>.Value | ||
Dim expectedFlowGraph = <![CDATA[ | ||
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. |
||
Block[B0] - Entry | ||
Statements (0) | ||
Next (Regular) Block[B1] | ||
Entering: {R1} | ||
.locals {R1} | ||
{ | ||
Locals: [item As C] | ||
CaptureIds: [0] | ||
Block[B1] - Block | ||
Predecessors: [B0] | ||
Statements (3) | ||
IFlowCaptureOperation: 0 (OperationKind.FlowCapture, Type: null, IsInvalid, IsImplicit) (Syntax: 'New C() With {.}') | ||
Value: | ||
IObjectCreationOperation (Constructor: Sub C..ctor()) (OperationKind.ObjectCreation, Type: C, IsInvalid) (Syntax: 'New C() With {.}') | ||
Arguments(0) | ||
Initializer: | ||
null | ||
ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: ?, IsInvalid) (Syntax: '.') | ||
Left: | ||
IInvalidOperation (OperationKind.Invalid, Type: ?, IsInvalid, IsImplicit) (Syntax: '.') | ||
Children(0) | ||
Right: | ||
IInvalidOperation (OperationKind.Invalid, Type: null, IsInvalid) (Syntax: '') | ||
Children(0) | ||
ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: C, IsInvalid, IsImplicit) (Syntax: 'item = New C() With {.}') | ||
Left: | ||
ILocalReferenceOperation: item (IsDeclaration: True) (OperationKind.LocalReference, Type: C, IsImplicit) (Syntax: 'item') | ||
Right: | ||
IFlowCaptureReferenceOperation: 0 (OperationKind.FlowCaptureReference, Type: C, IsInvalid, IsImplicit) (Syntax: 'New C() With {.}') | ||
Next (Regular) Block[B2] | ||
Leaving: {R1} | ||
} | ||
Block[B2] - Exit | ||
Predecessors: [B1] | ||
Statements (0) | ||
]]>.Value | ||
VerifyFlowGraphAndDiagnosticsForTest(Of MethodBlockSyntax)(source, expectedFlowGraph, expectedDiagnostics) | ||
End Sub | ||
|
||
<Fact()> | ||
Public Sub AnonymousObjectCreation_WithMissingMember_01() | ||
Dim source = <![CDATA[ | ||
Module Program | ||
Sub Main() 'BIND:"Sub Main()" | ||
Dim item = New With {.} | ||
End Sub | ||
End Module | ||
]]>.Value | ||
Dim expectedDiagnostics = <![CDATA[ | ||
BC30201: Expression expected. | ||
Dim item = New With {.} | ||
~ | ||
BC30203: Identifier expected. | ||
Dim item = New With {.} | ||
~ | ||
BC30984: '=' expected (object initializer). | ||
Dim item = New With {.} | ||
~ | ||
]]>.Value | ||
Dim expectedFlowGraph = <![CDATA[ | ||
Block[B0] - Entry | ||
Statements (0) | ||
Next (Regular) Block[B1] | ||
Entering: {R1} | ||
.locals {R1} | ||
{ | ||
Locals: [item As <anonymous type: $0 As ?>] | ||
CaptureIds: [0] | ||
Block[B1] - Block | ||
Predecessors: [B0] | ||
Statements (2) | ||
IFlowCaptureOperation: 0 (OperationKind.FlowCapture, Type: null, IsInvalid, IsImplicit) (Syntax: '') | ||
Value: | ||
IInvalidOperation (OperationKind.Invalid, Type: null, IsInvalid) (Syntax: '') | ||
Children(0) | ||
ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: <anonymous type: $0 As ?>, IsInvalid, IsImplicit) (Syntax: 'item = New With {.}') | ||
Left: | ||
ILocalReferenceOperation: item (IsDeclaration: True) (OperationKind.LocalReference, Type: <anonymous type: $0 As ?>, IsImplicit) (Syntax: 'item') | ||
Right: | ||
IAnonymousObjectCreationOperation (OperationKind.AnonymousObjectCreation, Type: <anonymous type: $0 As ?>, IsInvalid) (Syntax: 'New With {.}') | ||
Initializers(1): | ||
ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: ?, IsInvalid) (Syntax: '.') | ||
Left: | ||
IPropertyReferenceOperation: Property <anonymous type: $0 As ?>.$0 As ? (OperationKind.PropertyReference, Type: ?, IsInvalid) (Syntax: '') | ||
Instance Receiver: | ||
IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: <anonymous type: $0 As ?>, IsInvalid, IsImplicit) (Syntax: 'New With {.}') | ||
Right: | ||
IFlowCaptureReferenceOperation: 0 (OperationKind.FlowCaptureReference, Type: null, IsInvalid, IsImplicit) (Syntax: '') | ||
Next (Regular) Block[B2] | ||
Leaving: {R1} | ||
} | ||
Block[B2] - Exit | ||
Predecessors: [B1] | ||
Statements (0) | ||
]]>.Value | ||
VerifyFlowGraphAndDiagnosticsForTest(Of MethodBlockSyntax)(source, expectedFlowGraph, expectedDiagnostics) | ||
End Sub | ||
|
||
<Fact()> | ||
Public Sub AnonymousObjectCreation_WithMissingMember_02() | ||
Dim source = <![CDATA[ | ||
Module Program | ||
Sub Main() 'BIND:"Sub Main()" | ||
Dim item = New With {.a = 1, .b = .} | ||
End Sub | ||
End Module | ||
]]>.Value | ||
Dim expectedDiagnostics = <![CDATA[ | ||
BC30203: Identifier expected. | ||
Dim item = New With {.a = 1, .b = .} | ||
~ | ||
]]>.Value | ||
Dim expectedFlowGraph = <![CDATA[ | ||
Block[B0] - Entry | ||
Statements (0) | ||
Next (Regular) Block[B1] | ||
Entering: {R1} | ||
.locals {R1} | ||
{ | ||
Locals: [item As <anonymous type: a As System.Int32, b As ?>] | ||
CaptureIds: [0] [1] | ||
Block[B1] - Block | ||
Predecessors: [B0] | ||
Statements (3) | ||
IFlowCaptureOperation: 0 (OperationKind.FlowCapture, Type: null, IsImplicit) (Syntax: '1') | ||
Value: | ||
ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1) (Syntax: '1') | ||
IFlowCaptureOperation: 1 (OperationKind.FlowCapture, Type: null, IsInvalid, IsImplicit) (Syntax: '.') | ||
Value: | ||
IInvalidOperation (OperationKind.Invalid, Type: ?, IsInvalid) (Syntax: '.') | ||
Children(0) | ||
ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: <anonymous type: a As System.Int32, b As ?>, IsInvalid, IsImplicit) (Syntax: 'item = New ... 1, .b = .}') | ||
Left: | ||
ILocalReferenceOperation: item (IsDeclaration: True) (OperationKind.LocalReference, Type: <anonymous type: a As System.Int32, b As ?>, IsImplicit) (Syntax: 'item') | ||
Right: | ||
IAnonymousObjectCreationOperation (OperationKind.AnonymousObjectCreation, Type: <anonymous type: a As System.Int32, b As ?>, IsInvalid) (Syntax: 'New With {. ... 1, .b = .}') | ||
Initializers(2): | ||
ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.Int32, Constant: 1) (Syntax: '.a = 1') | ||
Left: | ||
IPropertyReferenceOperation: Property <anonymous type: a As System.Int32, b As ?>.a As System.Int32 (OperationKind.PropertyReference, Type: System.Int32) (Syntax: 'a') | ||
Instance Receiver: | ||
IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: <anonymous type: a As System.Int32, b As ?>, IsInvalid, IsImplicit) (Syntax: 'New With {. ... 1, .b = .}') | ||
Right: | ||
IFlowCaptureReferenceOperation: 0 (OperationKind.FlowCaptureReference, Type: System.Int32, Constant: 1, IsImplicit) (Syntax: '1') | ||
ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: ?, IsInvalid) (Syntax: '.b = .') | ||
Left: | ||
IPropertyReferenceOperation: Property <anonymous type: a As System.Int32, b As ?>.b As ? (OperationKind.PropertyReference, Type: ?) (Syntax: 'b') | ||
Instance Receiver: | ||
IInstanceReferenceOperation (ReferenceKind: ImplicitReceiver) (OperationKind.InstanceReference, Type: <anonymous type: a As System.Int32, b As ?>, IsInvalid, IsImplicit) (Syntax: 'New With {. ... 1, .b = .}') | ||
Right: | ||
IFlowCaptureReferenceOperation: 1 (OperationKind.FlowCaptureReference, Type: ?, IsInvalid, IsImplicit) (Syntax: '.') | ||
Next (Regular) Block[B2] | ||
Leaving: {R1} | ||
} | ||
Block[B2] - Exit | ||
Predecessors: [B1] | ||
Statements (0) | ||
]]>.Value | ||
VerifyFlowGraphAndDiagnosticsForTest(Of MethodBlockSyntax)(source, expectedFlowGraph, expectedDiagnostics) | ||
End Sub | ||
End Class | ||
End Namespace |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Alternatively, consider creating
InvalidOperation
when[property] Is Nothing
and reverting changes inGetAnonymousTypeCreationInitializers
. #ClosedThere 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.
I tried that initially. However,
TestOperationVisitor.VisitAnonymousObjectCreation()
expects the initializer target to be anIPropertyReferenceOperation
, and I assumed there might be consumers other than test code that also expect the same.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.
I think we should simply change the assertion in
TestOperationVisitor.VisitAnonymousObjectCreation
, what it is doing is mostly driven by implementation. When we are fixing bugs, we are changing shape ofIOperation
tree even for success scenarios, not to mention error scenarios. The binder says, it doesn't know what the property is (that is what the bound node returns) and I think we should stick with that rather than trying to re-guess what that property might be. Otherwise, we probably should fix what the bound node returns, so thatSemanticModel
andIOperation
tree produce consistent result.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.
Thanks. Based on our offline discussion, I've left this as is, and added a check of the SemanticModel to the tests.