' 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.VisualBasic.Syntax Imports Microsoft.CodeAnalysis.Test.Utilities Namespace Microsoft.CodeAnalysis.VisualBasic.UnitTests.Semantics Partial Public Class IOperationTests Inherits SemanticModelTestBase Public Sub TryCatchFinally_Basic() Dim source = 0 Throw ex Finally i = 1 End Try End Sub End Class]]>.Value Dim expectedOperationTree = 0') Left: IParameterReferenceOperation: i (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'i') Right: ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 0) (Syntax: '0') Handler: IBlockOperation (1 statements) (OperationKind.Block, Type: null, IsImplicit) (Syntax: 'Catch ex As ... Throw ex') IThrowOperation (OperationKind.Throw, Type: null) (Syntax: 'Throw ex') ILocalReferenceOperation: ex (OperationKind.LocalReference, Type: System.Exception) (Syntax: 'ex') Finally: IBlockOperation (1 statements) (OperationKind.Block, Type: null) (Syntax: 'Finally ... i = 1') IExpressionStatementOperation (OperationKind.ExpressionStatement, Type: null) (Syntax: 'i = 1') Expression: ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.Int32, IsImplicit) (Syntax: 'i = 1') Left: IParameterReferenceOperation: i (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'i') Right: ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1) (Syntax: '1') ]]>.Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatchFinally_Parent() Dim source = 0 Throw ex Finally i = 1 End Try End Sub End Class]]>.Value Dim expectedOperationTree = 0') Left: IParameterReferenceOperation: i (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'i') Right: ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 0) (Syntax: '0') Handler: IBlockOperation (1 statements) (OperationKind.Block, Type: null, IsImplicit) (Syntax: 'Catch ex As ... Throw ex') IThrowOperation (OperationKind.Throw, Type: null) (Syntax: 'Throw ex') ILocalReferenceOperation: ex (OperationKind.LocalReference, Type: System.Exception) (Syntax: 'ex') Finally: IBlockOperation (1 statements) (OperationKind.Block, Type: null) (Syntax: 'Finally ... i = 1') IExpressionStatementOperation (OperationKind.ExpressionStatement, Type: null) (Syntax: 'i = 1') Expression: ISimpleAssignmentOperation (OperationKind.SimpleAssignment, Type: System.Int32, IsImplicit) (Syntax: 'i = 1') Left: IParameterReferenceOperation: i (OperationKind.ParameterReference, Type: System.Int32) (Syntax: 'i') Right: ILiteralOperation (OperationKind.Literal, Type: System.Int32, Constant: 1) (Syntax: '1') ILabeledOperation (Label: exit) (OperationKind.Labeled, Type: null, IsImplicit) (Syntax: 'End Sub') Statement: null IReturnOperation (OperationKind.Return, Type: null, IsImplicit) (Syntax: 'End Sub') ReturnedValue: null ]]>.Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of MethodBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_SingleCatchClause() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_SingleCatchClauseAndFilter() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_MultipleCatchClausesWithDifferentCaughtTypes() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_MultipleCatchClausesWithDuplicateCaughtTypes() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = .Value VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_CatchClauseWithTypeExpression() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = .Value VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_CatchClauseWithLocalReferenceExpression() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_CatchClauseWithParameterReferenceExpression() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_CatchClauseWithFieldReferenceExpression() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = .Value VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_CatchClauseWithErrorExpression() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = .Value VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_CatchClauseWithInvalidExpression() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = .Value VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_CatchClauseWithoutCaughtTypeOrExceptionLocal() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_FinallyWithoutCatchClause() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_TryBlockWithLocalDeclaration() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_CatchBlockWithLocalDeclaration() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_FinallyWithLocalDeclaration() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_InvalidCaughtType() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = .Value VerifyOperationTreeAndDiagnosticsForTest(Of TryBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_GetOperationForCatchBlock() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of CatchBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_GetOperationForFinallyBlock() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of FinallyBlockSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_GetOperationForCatchExceptionIdentifier() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of IdentifierNameSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_GetOperationForCatchExceptionDeclaration() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of IdentifierNameSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_GetOperationForCatchFilterClause() Dim source = .Value Dim expectedOperationTree = .Value ' GetOperation return Nothing for CatchFilterClauseSyntax Assert.Null(GetOperationTreeForTest(Of CatchFilterClauseSyntax)(source).operation) End Sub Public Sub TryCatch_GetOperationForCatchFilterClauseExpression() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of BinaryExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_GetOperationForCatchStatement() Dim source = .Value ' GetOperation returns Nothing for CatchStatementSyntax Assert.Null(GetOperationTreeForTest(Of CatchStatementSyntax)(source).operation) End Sub Public Sub TryCatch_GetOperationForTryStatement() Dim source = .Value ' GetOperation returns Nothing for TryStatementSyntax Assert.Null(GetOperationTreeForTest(Of TryStatementSyntax)(source).operation) End Sub Public Sub TryCatch_GetOperationForEndTryStatement() Dim source = .Value ' GetOperation returns Nothing for End Try statement Assert.Null(GetOperationTreeForTest(Of EndBlockStatementSyntax)(source).operation) End Sub Public Sub TryCatch_GetOperationForFinallyStatement() Dim source = .Value ' GetOperation returns Nothing for FinallyStatementSyntax Assert.Null(GetOperationTreeForTest(Of FinallyStatementSyntax)(source).operation) End Sub Public Sub TryCatch_GetOperationForStatementInTryBlock() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of ExpressionStatementSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_GetOperationForStatementInCatchBlock() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of ExpressionStatementSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub TryCatch_GetOperationForStatementInFinallyBlock() Dim source = .Value Dim expectedOperationTree = .Value Dim expectedDiagnostics = String.Empty VerifyOperationTreeAndDiagnosticsForTest(Of ExpressionStatementSyntax)(source, expectedOperationTree, expectedDiagnostics) End Sub Public Sub ExceptionDispatch_45() Dim source = .Value Dim expectedDiagnostics = String.Empty Dim expectedFlowGraph = .Value VerifyFlowGraphAndDiagnosticsForTest(Of MethodBlockSyntax)(source, expectedFlowGraph, expectedDiagnostics, TestOptions.ReleaseExe) End Sub Public Sub FinallyDispatch_04() Dim source = .Value Dim expectedDiagnostics = .Value Dim expectedFlowGraph = .Value VerifyFlowGraphAndDiagnosticsForTest(Of MethodBlockSyntax)(source, expectedFlowGraph, expectedDiagnostics) End Sub End Class End Namespace