' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. Imports Microsoft.CodeAnalysis.Semantics Imports Microsoft.CodeAnalysis.Test.Utilities Imports Microsoft.CodeAnalysis.VisualBasic.Syntax Imports Roslyn.Test.Utilities Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics Partial Public Class IOperationTests Inherits SemanticModelTestBase Public Sub ParameterReference_TupleExpression() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of TupleExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_AnonymousObjectCreation() Dim source = .Value Dim expectedOperationTree = ) (Syntax: 'New With {' ... }') Initializers(2): ISimpleAssignmentExpression (OperationKind.SimpleAssignmentExpression, Type: System.Int32) (Syntax: 'Key .Amount = x') Left: IPropertyReferenceExpression: ReadOnly Property .Amount As System.Int32 (Static) (OperationKind.PropertyReferenceExpression, Type: System.Int32) (Syntax: 'Amount') Instance Receiver: null Right: IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.Int32) (Syntax: 'x') ISimpleAssignmentExpression (OperationKind.SimpleAssignmentExpression, Type: System.String) (Syntax: 'Key .Messag ... "Hello" + y') Left: IPropertyReferenceExpression: ReadOnly Property .Message As System.String (Static) (OperationKind.PropertyReferenceExpression, Type: System.String) (Syntax: 'Message') Instance Receiver: null Right: IBinaryOperatorExpression (BinaryOperationKind.StringConcatenate) (OperationKind.BinaryOperatorExpression, Type: System.String) (Syntax: '"Hello" + y') Left: ILiteralExpression (OperationKind.LiteralExpression, Type: System.String, Constant: "Hello") (Syntax: '"Hello"') Right: IParameterReferenceExpression: y (OperationKind.ParameterReferenceExpression, Type: System.String) (Syntax: 'y') ]]>.Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of AnonymousObjectCreationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_QueryExpression() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of QueryExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_QueryExpressionAggregateClause() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of QueryExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_QueryExpressionOrderByClause() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of QueryExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_QueryExpressionGroupByClause() Dim source = .Value Dim expectedOperationTree = , )(keySelector As System.Func(Of System.String, ), resultSelector As System.Func(Of , System.Collections.Generic.IEnumerable(Of System.String), )) As System.Collections.Generic.IEnumerable(Of )) (OperationKind.InvocationExpression, Type: System.Collections.Generic.IEnumerable(Of )) (Syntax: 'Group By w ... nto Count()') Instance Receiver: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Collections.Generic.IEnumerable(Of System.String)) (Syntax: 'y In x') Conversion: CommonConversion (Exists: False, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) Operand: IOperation: (OperationKind.None) (Syntax: 'y In x') Children(1): IOperation: (OperationKind.None) (Syntax: 'x') Children(1): IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.String()) (Syntax: 'x') Arguments(2): IArgument (ArgumentKind.DefaultValue, Matching Parameter: keySelector) (OperationKind.Argument) (Syntax: 'x') IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Func(Of System.String, )) (Syntax: 'x') Conversion: CommonConversion (Exists: False, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) Operand: IOperation: (OperationKind.None) (Syntax: 'x') Children(1): IAnonymousObjectCreationExpression (OperationKind.AnonymousObjectCreationExpression, Type: ) (Syntax: 'Group By w ... nto Count()') Initializers(2): IOperation: (OperationKind.None) (Syntax: 'w = x') Children(1): IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.String()) (Syntax: 'x') IOperation: (OperationKind.None) (Syntax: 'z = y') Children(1): IOperation: (OperationKind.None) (Syntax: 'y') InConversion: null OutConversion: null IArgument (ArgumentKind.DefaultValue, Matching Parameter: resultSelector) (OperationKind.Argument) (Syntax: 'Group By w ... nto Count()') IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Func(Of , System.Collections.Generic.IEnumerable(Of System.String), )) (Syntax: 'Group By w ... nto Count()') Conversion: CommonConversion (Exists: False, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null) Operand: IOperation: (OperationKind.None) (Syntax: 'Group By w ... nto Count()') Children(1): IAnonymousObjectCreationExpression (OperationKind.AnonymousObjectCreationExpression, Type: ) (Syntax: 'Group By w ... nto Count()') Initializers(3): IOperation: (OperationKind.None) (Syntax: 'w') IOperation: (OperationKind.None) (Syntax: 'z') IOperation: (OperationKind.None) (Syntax: 'Count()') Children(1): IOperation: (OperationKind.None) (Syntax: 'Count()') Children(1): IInvocationExpression ( Function System.Collections.Generic.IEnumerable(Of System.String).Count() As System.Int32) (OperationKind.InvocationExpression, Type: System.Int32) (Syntax: 'Count()') Instance Receiver: IParameterReferenceExpression: $VB$ItAnonymous (OperationKind.ParameterReferenceExpression, Type: System.Collections.Generic.IEnumerable(Of System.String)) (Syntax: 'Group By w ... nto Count()') Arguments(0) InConversion: null OutConversion: null ]]>.Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of QueryExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_ObjectAndCollectionInitializer() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of ObjectCreationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_DelegateCreationExpressionWithLambdaArgument() Dim source = .Value Dim expectedOperationTree = As System.Object IReturnStatement (OperationKind.ReturnStatement) (Syntax: 'x') ReturnedValue: IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.Object) (Syntax: 'x') ILabelStatement (Label: exit) (OperationKind.LabelStatement) (Syntax: 'Function() x') LabeledStatement: null IReturnStatement (OperationKind.ReturnStatement) (Syntax: 'Function() x') ReturnedValue: ILocalReferenceExpression: (OperationKind.LocalReferenceExpression, Type: System.Object) (Syntax: 'Function() x') ]]>.Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of ObjectCreationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_DelegateCreationExpressionWithMethodArgument() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of ObjectCreationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_DelegateCreationExpressionWithInvalidArgument() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = .Value VerifyOperationTreeAndDiagnosticsForTest(Of ObjectCreationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_NameOfExpression() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of NameOfExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_NameOfExpression_ErrorCase() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = .Value VerifyOperationTreeAndDiagnosticsForTest(Of NameOfExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_LateBoundIndexerAccess() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_LateBoundMemberAccess() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_LateBoundInvocation() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of InvocationExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_InterpolatedStringExpression() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of InterpolatedStringExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_MidAssignmentStatement() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of AssignmentStatementSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_MisplacedCaseStatement() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = .Value VerifyOperationTreeAndDiagnosticsForTest(Of CaseStatementSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_RedimStatement() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of ReDimStatementSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_EraseStatement() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of EraseStatementSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_UnstructuredExceptionHandlingStatement() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of MethodBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_LateAddressOfOperator() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of UnaryExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_NullableIsTrueOperator() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of MultiLineIfBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ParameterReference_NoPiaObjectCreation() Dim sources0 = Public Interface I Property P As Integer End Interface Public Class C Public Sub New(o As Object) End Sub End Class ]]> Dim sources1 = Dim compilation0 = CreateCompilationWithMscorlib(sources0) compilation0.AssertTheseDiagnostics() ' No errors for /r:_.dll Dim compilation1 = CreateCompilationWithReferences( sources1, references:={MscorlibRef, SystemRef, compilation0.EmitToImageReference(embedInteropTypes:=True)}) Dim expectedOperationTree = .Value Dim expectedDiagnostics = .Value VerifyOperationTreeAndDiagnosticsForTest(Of ObjectCreationExpressionSyntax)(compilation1, "a.vb", expectedOperationTree, expectedDiagnostics) End Sub End Class End Namespace