提交 c370da63 编写于 作者: M Manish Vasani

Address PR feedback

上级 ef007eb5
......@@ -306,11 +306,6 @@ private IInvocationExpression CreateBoundCallOperation(BoundCall boundCall)
private IOperation CreateBoundLocalOperation(BoundLocal boundLocal)
{
if (boundLocal.Syntax.Kind() == SyntaxKind.CatchDeclaration)
{
return CreateVariableDeclaration(boundLocal);
}
ILocalSymbol local = boundLocal.LocalSymbol;
bool isDeclaration = boundLocal.IsDeclaration;
SyntaxNode syntax = boundLocal.Syntax;
......@@ -1288,8 +1283,9 @@ private ITryStatement CreateBoundTryStatementOperation(BoundTryStatement boundTr
private ICatchClause CreateBoundCatchBlockOperation(BoundCatchBlock boundCatchBlock)
{
Lazy<IOperation> expressionDeclarationOrExpression = new Lazy<IOperation>(() => boundCatchBlock.ExceptionSourceOpt != null ? Create(boundCatchBlock.ExceptionSourceOpt) : null);
ITypeSymbol exceptionType = boundCatchBlock.ExceptionTypeOpt ?? ((CSharpCompilation)_semanticModel.Compilation).GetWellKnownType(WellKnownType.System_Exception);
var exceptionSourceOpt = (BoundLocal)boundCatchBlock.ExceptionSourceOpt;
Lazy<IOperation> expressionDeclarationOrExpression = new Lazy<IOperation>(() => exceptionSourceOpt != null ? CreateVariableDeclaration(exceptionSourceOpt) : null);
ITypeSymbol exceptionType = boundCatchBlock.ExceptionTypeOpt;
Lazy<IOperation> filter = new Lazy<IOperation>(() => Create(boundCatchBlock.ExceptionFilterOpt));
Lazy<IBlockStatement> handler = new Lazy<IBlockStatement>(() => (IBlockStatement)Create(boundCatchBlock.Body));
SyntaxNode syntax = boundCatchBlock.Syntax;
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Test.Utilities;
......@@ -366,7 +366,7 @@ static void M(object o)
ITryStatement (OperationKind.TryStatement) (Syntax: 'try ... }')
Body: IBlockStatement (0 statements) (OperationKind.BlockStatement) (Syntax: '{ ... }')
Catch clauses(1):
ICatchClause (Exception type: System.Exception) (OperationKind.CatchClause) (Syntax: 'catch ... }')
ICatchClause (Exception type: null) (OperationKind.CatchClause) (Syntax: 'catch ... }')
ExceptionDeclarationOrExpression: null
Filter: null
Handler: IBlockStatement (0 statements) (OperationKind.BlockStatement) (Syntax: '{ ... }')
......@@ -686,7 +686,7 @@ static void Main()
}
[CompilerTrait(CompilerFeature.IOperation)]
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/22299")]
[Fact]
public void TryCatch_GetOperationForCatchFilterClause()
{
string source = @"
......@@ -704,21 +704,45 @@ static void M(string s)
}
}
}
";
// GetOperation returns null for CatchFilterClauseSyntax
Assert.Null(GetOperationTreeForTest<CatchFilterClauseSyntax>(source));
}
[CompilerTrait(CompilerFeature.IOperation)]
[Fact]
public void TryCatch_GetOperationForCatchFilterClauseExpression()
{
string source = @"
using System;
class C
{
static void M(string s)
{
try
{
}
catch (Exception) when (/*<bind>*/s != null/*</bind>*/)
{
}
}
}
";
string expectedOperationTree = @"
Filter: IBinaryOperatorExpression (BinaryOperatorKind.NotEquals) (OperationKind.BinaryOperatorExpression, Type: System.Boolean) (Syntax: 's != null')
IBinaryOperatorExpression (BinaryOperatorKind.NotEquals) (OperationKind.BinaryOperatorExpression, Type: System.Boolean) (Syntax: 's != null')
Left: IParameterReferenceExpression: s (OperationKind.ParameterReferenceExpression, Type: System.String) (Syntax: 's')
Right: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.String, Constant: null) (Syntax: 'null')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: True, IsUserDefined: False) (MethodSymbol: null)
Operand: ILiteralExpression (OperationKind.LiteralExpression, Type: null, Constant: null) (Syntax: 'null')
Operand: ILiteralExpression (OperationKind.LiteralExpression, Type: null, Constant: null) (Syntax: 'null')
";
var expectedDiagnostics = DiagnosticDescription.None;
VerifyOperationTreeAndDiagnosticsForTest<CatchFilterClauseSyntax>(source, expectedOperationTree, expectedDiagnostics);
VerifyOperationTreeAndDiagnosticsForTest<BinaryExpressionSyntax>(source, expectedOperationTree, expectedDiagnostics);
}
[CompilerTrait(CompilerFeature.IOperation)]
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/22299")]
[Fact]
public void TryCatch_GetOperationForFinallyClause()
{
string source = @"
......@@ -738,20 +762,8 @@ static void M(string s)
}
}
";
string expectedOperationTree = @"
Finally: IBlockStatement (1 statements) (OperationKind.BlockStatement) (Syntax: '{ ... }')
IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'Console.WriteLine(s);')
Expression: IInvocationExpression (void System.Console.WriteLine(System.String value)) (OperationKind.InvocationExpression, Type: System.Void) (Syntax: 'Console.WriteLine(s)')
Instance Receiver: null
Arguments(1):
IArgument (ArgumentKind.Explicit, Matching Parameter: value) (OperationKind.Argument) (Syntax: 's')
IParameterReferenceExpression: s (OperationKind.ParameterReferenceExpression, Type: System.String) (Syntax: 's')
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
";
var expectedDiagnostics = DiagnosticDescription.None;
VerifyOperationTreeAndDiagnosticsForTest<FinallyClauseSyntax>(source, expectedOperationTree, expectedDiagnostics);
// GetOperation returns null for FinallyClauseSyntax
Assert.Null(GetOperationTreeForTest<FinallyClauseSyntax>(source));
}
}
}
......@@ -4352,7 +4352,7 @@ internal abstract partial class BaseTryStatement : Operation, ITryStatement
protected abstract IBlockStatement BodyImpl { get; }
protected abstract ImmutableArray<ICatchClause> CatchesImpl { get; }
protected abstract IBlockStatement FinallyHandlerImpl { get; }
protected abstract IBlockStatement FinallyImpl { get; }
public override IEnumerable<IOperation> Children
{
get
......@@ -4362,7 +4362,7 @@ public override IEnumerable<IOperation> Children
{
yield return catche;
}
yield return FinallyHandler;
yield return Finally;
}
}
/// <summary>
......@@ -4376,7 +4376,7 @@ public override IEnumerable<IOperation> Children
/// <summary>
/// Finally handler of the try.
/// </summary>
public IBlockStatement FinallyHandler => Operation.SetParentOperation(FinallyHandlerImpl, this);
public IBlockStatement Finally => Operation.SetParentOperation(FinallyImpl, this);
public override void Accept(OperationVisitor visitor)
{
visitor.VisitTryStatement(this);
......@@ -4397,12 +4397,12 @@ internal sealed partial class TryStatement : BaseTryStatement, ITryStatement
{
BodyImpl = body;
CatchesImpl = catches;
FinallyHandlerImpl = finallyHandler;
FinallyImpl = finallyHandler;
}
protected override IBlockStatement BodyImpl { get; }
protected override ImmutableArray<ICatchClause> CatchesImpl { get; }
protected override IBlockStatement FinallyHandlerImpl { get; }
protected override IBlockStatement FinallyImpl { get; }
}
/// <summary>
......@@ -4425,7 +4425,7 @@ public LazyTryStatement(Lazy<IBlockStatement> body, Lazy<ImmutableArray<ICatchCl
protected override ImmutableArray<ICatchClause> CatchesImpl => _lazyCatches.Value;
protected override IBlockStatement FinallyHandlerImpl => _lazyFinallyHandler.Value;
protected override IBlockStatement FinallyImpl => _lazyFinallyHandler.Value;
}
/// <summary>
......
......@@ -26,7 +26,7 @@ public interface ICatchClause : IOperation
/// 1. Declaration for the local catch variable bound to the caught exception (C# and VB) OR
/// 2. Null, indicating no declaration or expression (C# and VB)
/// 3. Reference to an existing local or parameter (VB) OR
/// 4. An error expression (VB)
/// 4. Other expression for error scenarios (VB)
/// </summary>
IOperation ExceptionDeclarationOrExpression { get; }
......
......@@ -24,7 +24,7 @@ public interface ITryStatement : IOperation
/// <summary>
/// Finally handler of the try.
/// </summary>
IBlockStatement FinallyHandler { get; }
IBlockStatement Finally { get; }
}
}
......@@ -141,7 +141,7 @@ public override IOperation VisitLockStatement(ILockStatement operation, object a
public override IOperation VisitTryStatement(ITryStatement operation, object argument)
{
return new TryStatement(Visit(operation.Body), VisitArray(operation.Catches), Visit(operation.FinallyHandler), ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit);
return new TryStatement(Visit(operation.Body), VisitArray(operation.Catches), Visit(operation.Finally), ((Operation)operation).SemanticModel, operation.Syntax, operation.Type, operation.ConstantValue, operation.IsImplicit);
}
public override IOperation VisitCatchClause(ICatchClause operation, object argument)
......
......@@ -421,7 +421,7 @@ Microsoft.CodeAnalysis.Semantics.ITranslatedQueryExpression.Expression.get -> Mi
Microsoft.CodeAnalysis.Semantics.ITryStatement
Microsoft.CodeAnalysis.Semantics.ITryStatement.Body.get -> Microsoft.CodeAnalysis.Semantics.IBlockStatement
Microsoft.CodeAnalysis.Semantics.ITryStatement.Catches.get -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.Semantics.ICatchClause>
Microsoft.CodeAnalysis.Semantics.ITryStatement.FinallyHandler.get -> Microsoft.CodeAnalysis.Semantics.IBlockStatement
Microsoft.CodeAnalysis.Semantics.ITryStatement.Finally.get -> Microsoft.CodeAnalysis.Semantics.IBlockStatement
Microsoft.CodeAnalysis.Semantics.ITupleExpression
Microsoft.CodeAnalysis.Semantics.ITupleExpression.Elements.get -> System.Collections.Immutable.ImmutableArray<Microsoft.CodeAnalysis.IOperation>
Microsoft.CodeAnalysis.Semantics.ITypeOfExpression
......
......@@ -1163,7 +1163,7 @@ protected static string GetOperationTreeForTest(CSharpCompilation compilation, I
return operation != null ? OperationTreeVerifier.GetOperationTree(compilation, operation) : null;
}
protected static string GetOperationTreeForTest<TSyntaxNode>(string testSrc, string expectedOperationTree, CSharpCompilationOptions compilationOptions = null, CSharpParseOptions parseOptions = null)
protected static string GetOperationTreeForTest<TSyntaxNode>(string testSrc, CSharpCompilationOptions compilationOptions = null, CSharpParseOptions parseOptions = null)
where TSyntaxNode : SyntaxNode
{
var compilation = CreateStandardCompilation(testSrc, new[] { SystemCoreRef, ValueTupleRef, SystemRuntimeFacadeRef }, options: compilationOptions ?? TestOptions.ReleaseDll, parseOptions: parseOptions);
......@@ -1182,7 +1182,7 @@ protected static void VerifyOperationTreeForTest<TSyntaxNode>(CSharpCompilation
protected static void VerifyOperationTreeForTest<TSyntaxNode>(string testSrc, string expectedOperationTree, CSharpCompilationOptions compilationOptions = null, CSharpParseOptions parseOptions = null)
where TSyntaxNode : SyntaxNode
{
var actualOperationTree = GetOperationTreeForTest<TSyntaxNode>(testSrc, expectedOperationTree, compilationOptions, parseOptions);
var actualOperationTree = GetOperationTreeForTest<TSyntaxNode>(testSrc, compilationOptions, parseOptions);
OperationTreeVerifier.Verify(expectedOperationTree, actualOperationTree);
}
......
......@@ -800,10 +800,6 @@ Namespace Microsoft.CodeAnalysis.Semantics
End Function
Private Function CreateBoundLocalOperation(boundLocal As BoundLocal) As IOperation
If boundLocal.Syntax.Kind = SyntaxKind.IdentifierName AndAlso boundLocal.Syntax.Parent?.Kind = SyntaxKind.CatchStatement Then
Return OperationFactory.CreateVariableDeclaration(boundLocal.LocalSymbol, initialValue:=Nothing, semanticModel:=_semanticModel, syntax:=boundLocal.Syntax)
End If
Dim local As ILocalSymbol = boundLocal.LocalSymbol
Dim isDeclaration As Boolean = False
Dim syntax As SyntaxNode = boundLocal.Syntax
......@@ -1082,7 +1078,15 @@ Namespace Microsoft.CodeAnalysis.Semantics
Private Function CreateBoundCatchBlockOperation(boundCatchBlock As BoundCatchBlock) As ICatchClause
Dim exceptionDeclarationOrExpression As Lazy(Of IOperation) = New Lazy(Of IOperation)(
Function() If(boundCatchBlock.ExceptionSourceOpt IsNot Nothing, Create(boundCatchBlock.ExceptionSourceOpt), Nothing))
Function()
If boundCatchBlock.LocalOpt IsNot Nothing Then
Dim exceptionSourceOpt = DirectCast(boundCatchBlock.ExceptionSourceOpt, BoundLocal)
Debug.Assert(boundCatchBlock.LocalOpt Is exceptionSourceOpt.LocalSymbol)
Return OperationFactory.CreateVariableDeclaration(exceptionSourceOpt.LocalSymbol, initialValue:=Nothing, semanticModel:=_semanticModel, syntax:=exceptionSourceOpt.Syntax)
Else
Return Create(boundCatchBlock.ExceptionSourceOpt)
End If
End Function)
Dim exceptionType As ITypeSymbol = If(boundCatchBlock.ExceptionSourceOpt?.Type, DirectCast(_semanticModel.Compilation, VisualBasicCompilation).GetWellKnownType(WellKnownType.System_Exception))
Dim filter As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundCatchBlock.ExceptionFilterOpt))
Dim handler As Lazy(Of IBlockStatement) = New Lazy(Of IBlockStatement)(Function() DirectCast(Create(boundCatchBlock.Body), IBlockStatement))
......
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
' 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
......@@ -319,7 +319,7 @@ BC30205: End of statement expected.
Imports System
Class C
Private Shared Sub M()
Dim e As Exception = Nothing
Dim e As IO.IOException = Nothing
Try'BIND:"Try"
Catch e
End Try
......@@ -330,10 +330,8 @@ End Class]]>.Value
ITryStatement (OperationKind.TryStatement) (Syntax: 'Try'BIND:"T ... End Try')
Body: IBlockStatement (0 statements) (OperationKind.BlockStatement) (Syntax: 'Try'BIND:"T ... End Try')
Catch clauses(1):
ICatchClause (Exception type: System.Exception) (OperationKind.CatchClause) (Syntax: 'Catch e')
ExceptionDeclarationOrExpression: IVariableDeclaration (1 variables) (OperationKind.VariableDeclaration) (Syntax: 'e')
Variables: Local_1: e As System.Exception
Initializer: null
ICatchClause (Exception type: System.IO.IOException) (OperationKind.CatchClause) (Syntax: 'Catch e')
ExceptionDeclarationOrExpression: ILocalReferenceExpression: e (OperationKind.LocalReferenceExpression, Type: System.IO.IOException) (Syntax: 'e')
Filter: null
Handler: IBlockStatement (0 statements) (OperationKind.BlockStatement) (Syntax: 'Catch e')
Finally: null
......@@ -350,7 +348,7 @@ ITryStatement (OperationKind.TryStatement) (Syntax: 'Try'BIND:"T ... End Try')
Dim source = <![CDATA[
Imports System
Class C
Private Shared Sub M(e As Exception)
Private Shared Sub M(e As IO.IOException)
Try'BIND:"Try"
Catch e
End Try
......@@ -361,8 +359,8 @@ End Class]]>.Value
ITryStatement (OperationKind.TryStatement) (Syntax: 'Try'BIND:"T ... End Try')
Body: IBlockStatement (0 statements) (OperationKind.BlockStatement) (Syntax: 'Try'BIND:"T ... End Try')
Catch clauses(1):
ICatchClause (Exception type: System.Exception) (OperationKind.CatchClause) (Syntax: 'Catch e')
ExceptionDeclarationOrExpression: IParameterReferenceExpression: e (OperationKind.ParameterReferenceExpression, Type: System.Exception) (Syntax: 'e')
ICatchClause (Exception type: System.IO.IOException) (OperationKind.CatchClause) (Syntax: 'Catch e')
ExceptionDeclarationOrExpression: IParameterReferenceExpression: e (OperationKind.ParameterReferenceExpression, Type: System.IO.IOException) (Syntax: 'e')
Filter: null
Handler: IBlockStatement (0 statements) (OperationKind.BlockStatement) (Syntax: 'Catch e')
Finally: null
......@@ -379,7 +377,7 @@ ITryStatement (OperationKind.TryStatement) (Syntax: 'Try'BIND:"T ... End Try')
Dim source = <![CDATA[
Imports System
Class C
Private e As Exception = Nothing
Private e As IO.IOException = Nothing
Private Sub M()
Try 'BIND:"Try"'BIND:"Try 'BIND:"Try""
......@@ -392,8 +390,8 @@ End Class]]>.Value
ITryStatement (OperationKind.TryStatement, IsInvalid) (Syntax: 'Try 'BIND:" ... End Try')
Body: IBlockStatement (0 statements) (OperationKind.BlockStatement, IsInvalid) (Syntax: 'Try 'BIND:" ... End Try')
Catch clauses(1):
ICatchClause (Exception type: System.Exception) (OperationKind.CatchClause, IsInvalid) (Syntax: 'Catch e')
ExceptionDeclarationOrExpression: IFieldReferenceExpression: C.e As System.Exception (OperationKind.FieldReferenceExpression, Type: System.Exception, IsInvalid) (Syntax: 'e')
ICatchClause (Exception type: System.IO.IOException) (OperationKind.CatchClause, IsInvalid) (Syntax: 'Catch e')
ExceptionDeclarationOrExpression: IFieldReferenceExpression: C.e As System.IO.IOException (OperationKind.FieldReferenceExpression, Type: System.IO.IOException, IsInvalid) (Syntax: 'e')
Instance Receiver: IInstanceReferenceExpression (OperationKind.InstanceReferenceExpression, Type: C, IsInvalid) (Syntax: 'e')
Filter: null
Handler: IBlockStatement (0 statements) (OperationKind.BlockStatement, IsInvalid) (Syntax: 'Catch e')
......@@ -795,6 +793,55 @@ IVariableDeclaration (1 variables) (OperationKind.VariableDeclaration) (Syntax:
VerifyOperationTreeAndDiagnosticsForTest(Of IdentifierNameSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact>
Public Sub TryCatch_GetOperationForCatchFilterClause()
Dim source = <![CDATA[
Imports System
Class C
Private Shared Sub M()
Try
Catch e As IO.IOException When e.Message IsNot Nothing'BIND:"When e.Message IsNot Nothing"
End Try
End Sub
End Class]]>.Value
Dim expectedOperationTree = <![CDATA[
]]>.Value
' GetOperation return Nothing for CatchFilterClauseSyntax
Assert.Null(GetOperationTreeForTest(Of CatchFilterClauseSyntax)(source).operation)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact>
Public Sub TryCatch_GetOperationForCatchFilterClauseExpression()
Dim source = <![CDATA[
Imports System
Class C
Private Shared Sub M()
Try
Catch e As IO.IOException When e.Message IsNot Nothing'BIND:"e.Message IsNot Nothing"
End Try
End Sub
End Class]]>.Value
Dim expectedOperationTree = <![CDATA[
IBinaryOperatorExpression (BinaryOperatorKind.NotEquals) (OperationKind.BinaryOperatorExpression, Type: System.Boolean) (Syntax: 'e.Message IsNot Nothing')
Left: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Object) (Syntax: 'e.Message')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: True, IsUserDefined: False) (MethodSymbol: null)
Operand: IPropertyReferenceExpression: ReadOnly Property System.Exception.Message As System.String (OperationKind.PropertyReferenceExpression, Type: System.String) (Syntax: 'e.Message')
Instance Receiver: ILocalReferenceExpression: e (OperationKind.LocalReferenceExpression, Type: System.IO.IOException) (Syntax: 'e')
Right: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Object, Constant: null) (Syntax: 'Nothing')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
Operand: ILiteralExpression (OperationKind.LiteralExpression, Type: null, Constant: null) (Syntax: 'Nothing')
]]>.Value
Dim expectedDiagnostics = String.Empty
VerifyOperationTreeAndDiagnosticsForTest(Of BinaryExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact>
Public Sub TryCatch_GetOperationForCatchStatement()
......@@ -829,6 +876,23 @@ End Class]]>.Value
Assert.Null(GetOperationTreeForTest(Of TryStatementSyntax)(source).operation)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact>
Public Sub TryCatch_GetOperationForEndTryStatement()
Dim source = <![CDATA[
Imports System
Class C
Private Shared Sub M()
Try
Catch e As IO.IOException When e.Message IsNot Nothing
End Try'BIND:"End Try"
End Sub
End Class]]>.Value
' GetOperation returns Nothing for End Try statement
Assert.Null(GetOperationTreeForTest(Of EndBlockStatementSyntax)(source).operation)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact>
Public Sub TryCatch_GetOperationForFinallyStatement()
......@@ -847,5 +911,97 @@ End Class]]>.Value
Assert.Null(GetOperationTreeForTest(Of FinallyStatementSyntax)(source).operation)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact>
Public Sub TryCatch_GetOperationForStatementInTryBlock()
Dim source = <![CDATA[
Imports System
Class C
Private Shared Sub M(s As String)
Try
Console.WriteLine(s)'BIND:"Console.WriteLine(s)"
Catch e As IO.IOException
End Try
End Sub
End Class]]>.Value
Dim expectedOperationTree = <![CDATA[
IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'Console.WriteLine(s)')
Expression: IInvocationExpression (Sub System.Console.WriteLine(value As System.String)) (OperationKind.InvocationExpression, Type: System.Void) (Syntax: 'Console.WriteLine(s)')
Instance Receiver: null
Arguments(1):
IArgument (ArgumentKind.Explicit, Matching Parameter: value) (OperationKind.Argument) (Syntax: 's')
IParameterReferenceExpression: s (OperationKind.ParameterReferenceExpression, Type: System.String) (Syntax: 's')
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
]]>.Value
Dim expectedDiagnostics = String.Empty
VerifyOperationTreeAndDiagnosticsForTest(Of ExpressionStatementSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact>
Public Sub TryCatch_GetOperationForStatementInCatchBlock()
Dim source = <![CDATA[
Imports System
Class C
Private Shared Sub M()
Try
Catch e As IO.IOException
Console.WriteLine(e)'BIND:"Console.WriteLine(e)"
End Try
End Sub
End Class]]>.Value
Dim expectedOperationTree = <![CDATA[
IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'Console.WriteLine(e)')
Expression: IInvocationExpression (Sub System.Console.WriteLine(value As System.Object)) (OperationKind.InvocationExpression, Type: System.Void) (Syntax: 'Console.WriteLine(e)')
Instance Receiver: null
Arguments(1):
IArgument (ArgumentKind.Explicit, Matching Parameter: value) (OperationKind.Argument) (Syntax: 'e')
IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Object) (Syntax: 'e')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: True, IsUserDefined: False) (MethodSymbol: null)
Operand: ILocalReferenceExpression: e (OperationKind.LocalReferenceExpression, Type: System.IO.IOException) (Syntax: 'e')
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
]]>.Value
Dim expectedDiagnostics = String.Empty
VerifyOperationTreeAndDiagnosticsForTest(Of ExpressionStatementSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact>
Public Sub TryCatch_GetOperationForStatementInFinallyBlock()
Dim source = <![CDATA[
Imports System
Class C
Private Shared Sub M(s As String)
Try
Finally
Console.WriteLine(s)'BIND:"Console.WriteLine(s)"
End Try
End Sub
End Class]]>.Value
Dim expectedOperationTree = <![CDATA[
IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'Console.WriteLine(s)')
Expression: IInvocationExpression (Sub System.Console.WriteLine(value As System.String)) (OperationKind.InvocationExpression, Type: System.Void) (Syntax: 'Console.WriteLine(s)')
Instance Receiver: null
Arguments(1):
IArgument (ArgumentKind.Explicit, Matching Parameter: value) (OperationKind.Argument) (Syntax: 's')
IParameterReferenceExpression: s (OperationKind.ParameterReferenceExpression, Type: System.String) (Syntax: 's')
InConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
OutConversion: CommonConversion (Exists: True, IsIdentity: True, IsNumeric: False, IsReference: False, IsUserDefined: False) (MethodSymbol: null)
]]>.Value
Dim expectedDiagnostics = String.Empty
VerifyOperationTreeAndDiagnosticsForTest(Of ExpressionStatementSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
End Class
End Namespace
......@@ -564,13 +564,14 @@ public override void VisitTryStatement(ITryStatement operation)
Visit(operation.Body, "Body");
VisitArray(operation.Catches, "Catch clauses", logElementCount: true);
Visit(operation.FinallyHandler, "Finally");
Visit(operation.Finally, "Finally");
}
public override void VisitCatchClause(ICatchClause operation)
{
LogString(nameof(ICatchClause));
LogString($" (Exception type: {operation.ExceptionType?.ToTestDisplayString()})");
var exceptionTypeStr = operation.ExceptionType != null ? operation.ExceptionType.ToTestDisplayString() : "null";
LogString($" (Exception type: {exceptionTypeStr})");
LogCommonPropertiesAndNewLine(operation);
Visit(operation.ExceptionDeclarationOrExpression, "ExceptionDeclarationOrExpression");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册