Added support for RValues in VB With Expressions.

上级 ef52c548
......@@ -234,6 +234,10 @@ Namespace Microsoft.CodeAnalysis.Semantics
Return Create(DirectCast(boundNode, BoundAnonymousTypeFieldInitializer).Value)
Case BoundKind.AnonymousTypePropertyAccess
Return CreateBoundAnonymousTypePropertyAccessOperation(DirectCast(boundNode, BoundAnonymousTypePropertyAccess))
Case BoundKind.WithLValueExpressionPlaceholder
Return CreateBoundWithLValueExpressionPlaceholder(DirectCast(boundNode, BoundWithLValueExpressionPlaceholder))
Case BoundKind.WithRValueExpressionPlaceholder
Return CreateBoundWithRValueExpressionPlaceholder(DirectCast(boundNode, BoundWithRValueExpressionPlaceholder))
Case Else
Dim constantValue = ConvertToOptional(TryCast(boundNode, BoundExpression)?.ConstantValueOpt)
Dim isImplicit As Boolean = boundNode.WasCompilerGenerated
......@@ -678,13 +682,6 @@ Namespace Microsoft.CodeAnalysis.Semantics
Function()
If boundPropertyAccess.PropertySymbol.IsShared Then
Return Nothing
ElseIf boundPropertyAccess.ReceiverOpt IsNot Nothing AndAlso
boundPropertyAccess.ReceiverOpt.Kind = BoundKind.WithLValueExpressionPlaceholder Then
Return New InstanceReferenceExpression(semanticModel:=_semanticModel,
syntax:=boundPropertyAccess.ReceiverOpt.Syntax,
type:=boundPropertyAccess.ReceiverOpt.Type,
constantValue:=Nothing,
isImplicit:=boundPropertyAccess.WasCompilerGenerated)
Else
Return Create(boundPropertyAccess.ReceiverOpt)
End If
......@@ -704,6 +701,22 @@ Namespace Microsoft.CodeAnalysis.Semantics
Return New LazyPropertyReferenceExpression([property], instance, [property], argumentsInEvaluationOrder, _semanticModel, syntax, type, constantValue, isImplicit)
End Function
Private Function CreateBoundWithLValueExpressionPlaceholder(boundWithLValueExpressionPlaceholder As BoundWithLValueExpressionPlaceholder) As IInstanceReferenceExpression
Dim syntax As SyntaxNode = boundWithLValueExpressionPlaceholder.Syntax
Dim type As ITypeSymbol = boundWithLValueExpressionPlaceholder.Type
Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundWithLValueExpressionPlaceholder.ConstantValueOpt)
Dim isImplicit As Boolean = boundWithLValueExpressionPlaceholder.WasCompilerGenerated
Return New InstanceReferenceExpression(_semanticModel, syntax, type, constantValue, isImplicit)
End Function
Private Function CreateBoundWithRValueExpressionPlaceholder(boundWithRValueExpressionPlaceholder As BoundWithRValueExpressionPlaceholder) As IInstanceReferenceExpression
Dim syntax As SyntaxNode = boundWithRValueExpressionPlaceholder.Syntax
Dim type As ITypeSymbol = boundWithRValueExpressionPlaceholder.Type
Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundWithRValueExpressionPlaceholder.ConstantValueOpt)
Dim isImplicit As Boolean = boundWithRValueExpressionPlaceholder.WasCompilerGenerated
Return New InstanceReferenceExpression(_semanticModel, syntax, type, constantValue, isImplicit)
End Function
Private Function CreateBoundEventAccessOperation(boundEventAccess As BoundEventAccess) As IEventReferenceExpression
Dim instance As Lazy(Of IOperation) = New Lazy(Of IOperation)(
Function()
......
......@@ -60,7 +60,7 @@ IBlockStatement (9 statements, 7 locals) (OperationKind.BlockStatement, IsInvali
Initializers(1):
ISimpleAssignmentExpression (OperationKind.SimpleAssignmentExpression, Type: System.Int32) (Syntax: '.Field = 2')
Left: IFieldReferenceExpression: F.Field As System.Int32 (OperationKind.FieldReferenceExpression, Type: System.Int32) (Syntax: 'Field')
Instance Receiver: IOperation: (OperationKind.None) (Syntax: 'New F() Wit ... .Field = 2}')
Instance Receiver: IInstanceReferenceExpression (OperationKind.InstanceReferenceExpression, Type: F) (Syntax: 'New F() Wit ... .Field = 2}')
Right: ILiteralExpression (OperationKind.LiteralExpression, Type: System.Int32, Constant: 2) (Syntax: '2')
IVariableDeclarationStatement (1 declarations) (OperationKind.VariableDeclarationStatement) (Syntax: 'Dim x3 = Ne ... erty1 = ""}')
IVariableDeclaration (1 variables) (OperationKind.VariableDeclaration) (Syntax: 'x3')
......@@ -86,7 +86,7 @@ IBlockStatement (9 statements, 7 locals) (OperationKind.BlockStatement, IsInvali
Right: ILiteralExpression (OperationKind.LiteralExpression, Type: System.String, Constant: "") (Syntax: '""')
ISimpleAssignmentExpression (OperationKind.SimpleAssignmentExpression, Type: System.Int32) (Syntax: '.Field = 2')
Left: IFieldReferenceExpression: F.Field As System.Int32 (OperationKind.FieldReferenceExpression, Type: System.Int32) (Syntax: 'Field')
Instance Receiver: IOperation: (OperationKind.None) (Syntax: 'New F() Wit ... .Field = 2}')
Instance Receiver: IInstanceReferenceExpression (OperationKind.InstanceReferenceExpression, Type: F) (Syntax: 'New F() Wit ... .Field = 2}')
Right: ILiteralExpression (OperationKind.LiteralExpression, Type: System.Int32, Constant: 2) (Syntax: '2')
IVariableDeclarationStatement (1 declarations) (OperationKind.VariableDeclarationStatement) (Syntax: 'Dim x5 = Ne ... ld = True}}')
IVariableDeclaration (1 variables) (OperationKind.VariableDeclaration) (Syntax: 'x5')
......@@ -104,7 +104,7 @@ IBlockStatement (9 statements, 7 locals) (OperationKind.BlockStatement, IsInvali
Initializers(1):
ISimpleAssignmentExpression (OperationKind.SimpleAssignmentExpression, Type: System.Boolean) (Syntax: '.Field = True')
Left: IFieldReferenceExpression: B.Field As System.Boolean (OperationKind.FieldReferenceExpression, Type: System.Boolean) (Syntax: 'Field')
Instance Receiver: IOperation: (OperationKind.None) (Syntax: 'New B() Wit ... eld = True}')
Instance Receiver: IInstanceReferenceExpression (OperationKind.InstanceReferenceExpression, Type: B) (Syntax: 'New B() Wit ... eld = True}')
Right: ILiteralExpression (OperationKind.LiteralExpression, Type: System.Boolean, Constant: True) (Syntax: 'True')
IVariableDeclarationStatement (1 declarations) (OperationKind.VariableDeclarationStatement, IsInvalid) (Syntax: 'Dim e1 = Ne ... perty2 = 1}')
IVariableDeclaration (1 variables) (OperationKind.VariableDeclaration) (Syntax: 'e1')
......
......@@ -10,7 +10,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub PropertyReferenceExpression_PropertyReferenceInDerivedTypeUsesDerivedTypeAsInstanceType()
Public Sub PropertyReferenceExpression_PropertyReferenceInWithDerivedTypeUsesDerivedTypeAsInstanceType_LValue()
Dim source = <![CDATA[
Option Strict On
Module M1
......@@ -36,5 +36,36 @@ IPropertyReferenceExpression: Property M1.C1.P1 As System.Object (OperationKind.
VerifyOperationTreeAndDiagnosticsForTest(Of IdentifierNameSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub PropertyReferenceExpression_PropertyReferenceInWithDerivedTypeUsesDerivedTypeAsInstanceType_RValue()
Dim source = <![CDATA[
Option Strict On
Module M1
Sub Method1()
Dim c2 As C2 = New C2 With {.P2 = .P1}'BIND:".P1"
c2.P1 = Nothing
End Sub
Class C1
Public Overridable Property P1 As Object
Public Property P2 As Object
End Class
Class C2
Inherits C1
End Class
End Module]]>.Value
Dim expectedOperationTree = <![CDATA[
IPropertyReferenceExpression: Property M1.C1.P1 As System.Object (OperationKind.PropertyReferenceExpression, Type: System.Object) (Syntax: '.P1')
Instance Receiver: IInstanceReferenceExpression (OperationKind.InstanceReferenceExpression, Type: M1.C2) (Syntax: 'New C2 With {.P2 = .P1}')
]]>.Value
Dim expectedDiagnostics = String.Empty
VerifyOperationTreeAndDiagnosticsForTest(Of MemberAccessExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册