提交 90715eea 编写于 作者: H Heejae Chang

fixed test failure after merging

addresses more PR feedbacks
上级 2ced3ea7
......@@ -1020,13 +1020,10 @@ private IOperation GetStatementOrRootOperation(CSharpSyntaxNode node, Cancellati
{
Debug.Assert(node == GetBindingRootOrInitializer(node));
CSharpSyntaxNode bindableNode;
BoundNode lowestBoundNode;
BoundNode highestBoundNode;
GetBoundNodes(node, out bindableNode, out lowestBoundNode, out highestBoundNode, out _);
GetBoundNodes(node, out _, out _, out highestBoundNode, out _);
BoundNode result = highestBoundNode ?? lowestBoundNode;
BoundNode result = highestBoundNode;
// The CSharp operation factory assumes that UnboundLambda will be bound for error recovery and never be passed to the factory
// as the start of a tree to get operations for. This is guaranteed by the builder that populates the node map, as it will call
......@@ -1603,7 +1600,7 @@ private static Binder GetQueryEnclosingBinder(int position, CSharpSyntaxNode sta
}
while (node != null);
done:
done:
return GetEnclosingBinderInternalWithinRoot(AdjustStartingNodeAccordingToNewRoot(startingNode, queryClause.Syntax),
position, queryClause.Binder, queryClause.Syntax);
}
......
......@@ -840,7 +840,9 @@ private IInvalidExpression CreateBoundBadExpressionOperation(BoundBadExpression
// We match semantic model here: if the expression IsMissing, we have a null type, rather than the ErrorType of the bound node.
ITypeSymbol type = syntax.IsMissing ? null : boundBadExpression.Type;
Optional<object> constantValue = ConvertToOptional(boundBadExpression.ConstantValue);
bool isImplicit = boundBadExpression.WasCompilerGenerated;
// if child has syntax node point to same syntax node as bad expression, then this invalid expression is implicit
bool isImplicit = boundBadExpression.WasCompilerGenerated || boundBadExpression.ChildBoundNodes.Any(e => e?.Syntax == boundBadExpression.Syntax);
return new LazyInvalidExpression(children, _semanticModel, syntax, type, constantValue, isImplicit);
}
......@@ -1314,7 +1316,9 @@ private IInvalidStatement CreateBoundBadStatementOperation(BoundBadStatement bou
SyntaxNode syntax = boundBadStatement.Syntax;
ITypeSymbol type = null;
Optional<object> constantValue = default(Optional<object>);
bool isImplicit = boundBadStatement.WasCompilerGenerated;
// if child has syntax node point to same syntax node as bad statement, then this invalid statement is implicit
bool isImplicit = boundBadStatement.WasCompilerGenerated || boundBadStatement.ChildBoundNodes.Any(e => e?.Syntax == boundBadStatement.Syntax);
return new LazyInvalidStatement(children, _semanticModel, syntax, type, constantValue, isImplicit);
}
......
......@@ -49,6 +49,40 @@ static void F()
VerifyOperationTreeAndDiagnosticsForTest<LocalDeclarationStatementSyntax>(source, expectedOperationTree, expectedDiagnostics);
}
[CompilerTrait(CompilerFeature.IOperation)]
[Fact]
public void IAnonymousFunctionExpression_BoundLambda_HasValidLambdaExpressionTree2()
{
string source = @"
using System;
class Program
{
static void Main(string[] args)
{
Action x = /*<bind>*/() => F();/*</bind>*/
}
static void F()
{
}
}
";
string expectedOperationTree = @"
IAnonymousFunctionExpression (Symbol: lambda expression) (OperationKind.AnonymousFunctionExpression, Type: null) (Syntax: '() => F()')
IBlockStatement (2 statements) (OperationKind.BlockStatement) (Syntax: 'F()')
IExpressionStatement (OperationKind.ExpressionStatement) (Syntax: 'F()')
Expression: IInvocationExpression (void Program.F()) (OperationKind.InvocationExpression, Type: System.Void) (Syntax: 'F()')
Instance Receiver: null
Arguments(0)
IReturnStatement (OperationKind.ReturnStatement) (Syntax: 'F()')
ReturnedValue: null
";
var expectedDiagnostics = DiagnosticDescription.None;
VerifyOperationTreeAndDiagnosticsForTest<ParenthesizedLambdaExpressionSyntax>(source, expectedOperationTree, expectedDiagnostics);
}
[CompilerTrait(CompilerFeature.IOperation)]
[Fact]
public void IAnonymousFunctionExpression_UnboundLambdaAsVar_HasValidLambdaExpressionTree()
......
......@@ -1446,15 +1446,13 @@ void M1()
}
";
string expectedOperationTree = @"
IInvalidExpression (OperationKind.InvalidExpression, Type: System.Int32, IsInvalid) (Syntax: 'this[10]')
Children(1):
IPropertyReferenceExpression: System.Int32 P.this[System.Int32 index] { set; } (OperationKind.PropertyReferenceExpression, Type: System.Int32, IsInvalid) (Syntax: 'this[10]')
Instance Receiver: IInstanceReferenceExpression (OperationKind.InstanceReferenceExpression, Type: P, IsInvalid) (Syntax: 'this')
Arguments(1):
IArgument (ArgumentKind.Explicit, Matching Parameter: null) (OperationKind.Argument, IsInvalid) (Syntax: '10')
ILiteralExpression (OperationKind.LiteralExpression, Type: System.Int32, Constant: 10, IsInvalid) (Syntax: '10')
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)
IPropertyReferenceExpression: System.Int32 P.this[System.Int32 index] { set; } (OperationKind.PropertyReferenceExpression, Type: System.Int32, IsInvalid) (Syntax: 'this[10]')
Instance Receiver: IInstanceReferenceExpression (OperationKind.InstanceReferenceExpression, Type: P, IsInvalid) (Syntax: 'this')
Arguments(1):
IArgument (ArgumentKind.Explicit, Matching Parameter: null) (OperationKind.Argument, IsInvalid) (Syntax: '10')
ILiteralExpression (OperationKind.LiteralExpression, Type: System.Int32, Constant: 10, IsInvalid) (Syntax: '10')
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 = new DiagnosticDescription[] {
// file.cs(12,27): error CS0154: The property or indexer 'P.this[int]' cannot be used in this context because it lacks the get accessor
......@@ -1485,15 +1483,13 @@ void M1()
}
";
string expectedOperationTree = @"
IInvalidExpression (OperationKind.InvalidExpression, Type: System.Int32, IsInvalid) (Syntax: 'this[10]')
Children(1):
IPropertyReferenceExpression: System.Int32 P.this[System.Int32 index] { get; } (OperationKind.PropertyReferenceExpression, Type: System.Int32, IsInvalid) (Syntax: 'this[10]')
Instance Receiver: IInstanceReferenceExpression (OperationKind.InstanceReferenceExpression, Type: P, IsInvalid) (Syntax: 'this')
Arguments(1):
IArgument (ArgumentKind.Explicit, Matching Parameter: null) (OperationKind.Argument, IsInvalid) (Syntax: '10')
ILiteralExpression (OperationKind.LiteralExpression, Type: System.Int32, Constant: 10, IsInvalid) (Syntax: '10')
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)
IPropertyReferenceExpression: System.Int32 P.this[System.Int32 index] { get; } (OperationKind.PropertyReferenceExpression, Type: System.Int32, IsInvalid) (Syntax: 'this[10]')
Instance Receiver: IInstanceReferenceExpression (OperationKind.InstanceReferenceExpression, Type: P, IsInvalid) (Syntax: 'this')
Arguments(1):
IArgument (ArgumentKind.Explicit, Matching Parameter: null) (OperationKind.Argument, IsInvalid) (Syntax: '10')
ILiteralExpression (OperationKind.LiteralExpression, Type: System.Int32, Constant: 10, IsInvalid) (Syntax: '10')
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 = new DiagnosticDescription[] {
......
......@@ -885,10 +885,7 @@ public I F(object x)
references: new[] { MscorlibRef, SystemRef, compilation0.EmitToImageReference(embedInteropTypes: true) });
string expectedOperationTree = @"
IInvalidExpression (OperationKind.InvalidExpression, Type: I, IsInvalid) (Syntax: 'new I(x)')
Children(2):
IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.Object, IsInvalid) (Syntax: 'x')
IOperation: (OperationKind.None, IsInvalid) (Syntax: 'new I(x)')
IOperation: (OperationKind.None, IsInvalid) (Syntax: 'new I(x)')
";
var expectedDiagnostics = new DiagnosticDescription[] {
// (6,25): error CS1729: 'I' does not contain a constructor that takes 1 arguments
......
// 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;
......@@ -1053,7 +1053,7 @@ static bool TakeOutParam<T>(T y, out T x)
WhenFalse: ILiteralExpression (OperationKind.LiteralExpression, Type: System.Int32, Constant: 2) (Syntax: '2')
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)
IArgument (ArgumentKind.Explicit, Matching Parameter: x) (OperationKind.Argument) (Syntax: 'var x1')
IArgument (ArgumentKind.Explicit, Matching Parameter: x) (OperationKind.Argument) (Syntax: 'out var x1')
ILocalReferenceExpression: x1 (IsDeclaration: True) (OperationKind.LocalReferenceExpression, Type: System.Int32) (Syntax: 'var x1')
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)
......
......@@ -794,6 +794,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Function
Friend Overrides Function GetOperationWorker(node As VisualBasicSyntaxNode, cancellationToken As CancellationToken) As IOperation
' see whether we can bind smaller scope than GetBindingRoot to make perf better
Dim bindingRoot = DirectCast(GetBindingRoot(node), VisualBasicSyntaxNode)
Dim statementOrRootOperation As IOperation = GetStatementOrRootOperation(bindingRoot, cancellationToken)
......@@ -809,7 +810,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Debug.Assert(node Is GetBindingRoot(node))
Dim summary As BoundNodeSummary = GetBoundNodeSummary(node)
Dim result As BoundNode = If(summary.HighestBoundNode, summary.LowestBoundNode)
Dim result As BoundNode = summary.HighestBoundNode
Return _operationFactory.Create(result)
End Function
......
......@@ -472,7 +472,9 @@ Namespace Microsoft.CodeAnalysis.Semantics
' We match semantic model here: If the Then expression IsMissing, we have a null type, rather than the ErrorType Of the bound node.
Dim type As ITypeSymbol = If(syntax.IsMissing, Nothing, boundBadExpression.Type)
Dim constantValue As [Optional](Of Object) = ConvertToOptional(boundBadExpression.ConstantValueOpt)
Dim isImplicit As Boolean = boundBadExpression.WasCompilerGenerated
' if child has syntax node point to same syntax node as bad expression, then this invalid expression Is implicit
Dim isImplicit = boundBadExpression.WasCompilerGenerated OrElse boundBadExpression.ChildBoundNodes.Any(Function(e) e?.Syntax Is boundBadExpression.Syntax)
Return New LazyInvalidExpression(children, _semanticModel, syntax, type, constantValue, isImplicit)
End Function
......@@ -925,7 +927,7 @@ Namespace Microsoft.CodeAnalysis.Semantics
Dim condition As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundDoLoopStatement.ConditionOpt))
Dim body As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function() Create(boundDoLoopStatement.Body))
Dim ignoredConditionOpt As Lazy(Of IOperation) = New Lazy(Of IOperation)(Function()
If doLoopKind = doLoopKind.Invalid Then
If doLoopKind = DoLoopKind.Invalid Then
Debug.Assert(boundDoLoopStatement.TopConditionOpt IsNot Nothing)
Debug.Assert(boundDoLoopStatement.BottomConditionOpt IsNot Nothing)
Debug.Assert(boundDoLoopStatement.ConditionOpt Is boundDoLoopStatement.TopConditionOpt)
......@@ -1059,7 +1061,9 @@ Namespace Microsoft.CodeAnalysis.Semantics
Dim syntax As SyntaxNode = boundBadStatement.Syntax
Dim type As ITypeSymbol = Nothing
Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
Dim isImplicit As Boolean = boundBadStatement.WasCompilerGenerated
' if child has syntax node point to same syntax node as bad statement, then this invalid statement Is implicit
Dim isImplicit = boundBadStatement.WasCompilerGenerated OrElse boundBadStatement.ChildBoundNodes.Any(Function(e) e?.Syntax Is boundBadStatement.Syntax)
Return New LazyInvalidStatement(children, _semanticModel, syntax, type, constantValue, isImplicit)
End Function
......@@ -1124,7 +1128,7 @@ Namespace Microsoft.CodeAnalysis.Semantics
Private Function CreateBoundGotoStatementOperation(boundGotoStatement As BoundGotoStatement) As IBranchStatement
Dim target As ILabelSymbol = boundGotoStatement.Label
Dim branchKind As BranchKind = branchKind.GoTo
Dim branchKind As BranchKind = BranchKind.GoTo
Dim syntax As SyntaxNode = boundGotoStatement.Syntax
Dim type As ITypeSymbol = Nothing
Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
......@@ -1134,7 +1138,7 @@ Namespace Microsoft.CodeAnalysis.Semantics
Private Function CreateBoundContinueStatementOperation(boundContinueStatement As BoundContinueStatement) As IBranchStatement
Dim target As ILabelSymbol = boundContinueStatement.Label
Dim branchKind As BranchKind = branchKind.Continue
Dim branchKind As BranchKind = BranchKind.Continue
Dim syntax As SyntaxNode = boundContinueStatement.Syntax
Dim type As ITypeSymbol = Nothing
Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
......@@ -1144,7 +1148,7 @@ Namespace Microsoft.CodeAnalysis.Semantics
Private Function CreateBoundExitStatementOperation(boundExitStatement As BoundExitStatement) As IBranchStatement
Dim target As ILabelSymbol = boundExitStatement.Label
Dim branchKind As BranchKind = branchKind.Break
Dim branchKind As BranchKind = BranchKind.Break
Dim syntax As SyntaxNode = boundExitStatement.Syntax
Dim type As ITypeSymbol = Nothing
Dim constantValue As [Optional](Of Object) = New [Optional](Of Object)()
......
......@@ -404,5 +404,40 @@ BC30581: 'AddressOf' expression cannot be converted to 'Integer' because 'Intege
VerifyParentOperations(model)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact()>
Public Sub TestCatchClause()
Dim source = <![CDATA[
Imports System
Module Program
Sub Main(args As String())
Try
Main(Nothing)
Catch ex As Exception When ex Is Nothing'BIND:"Catch ex As Exception When ex Is Nothing"
End Try
End Sub
End Module]]>.Value
Dim expectedOperationTree = <![CDATA[
ICatchClause (Exception type: System.Exception, Exception local: ex As System.Exception) (OperationKind.CatchClause) (Syntax: 'Catch ex As ... Is Nothing')
Filter: IBinaryOperatorExpression (BinaryOperatorKind.Equals) (OperationKind.BinaryOperatorExpression, Type: System.Boolean) (Syntax: 'ex Is Nothing')
Left: IConversionExpression (Implicit, TryCast: False, Unchecked) (OperationKind.ConversionExpression, Type: System.Object) (Syntax: 'ex')
Conversion: CommonConversion (Exists: True, IsIdentity: False, IsNumeric: False, IsReference: True, IsUserDefined: False) (MethodSymbol: null)
Operand: ILocalReferenceExpression: ex (OperationKind.LocalReferenceExpression, Type: System.Exception) (Syntax: 'ex')
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')
Handler: IBlockStatement (0 statements) (OperationKind.BlockStatement) (Syntax: 'Catch ex As ... Is Nothing')
]]>.Value
Dim expectedDiagnostics = String.Empty
VerifyOperationTreeAndDiagnosticsForTest(Of CatchBlockSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
End Class
End Namespace
......@@ -659,12 +659,10 @@ Friend Class [Class]
End Class]]>.Value
Dim expectedOperationTree = <![CDATA[
IInvalidStatement (OperationKind.InvalidStatement, IsInvalid) (Syntax: 'Case x')
IOperation: (OperationKind.None, IsInvalid) (Syntax: 'Case x')
Children(1):
IOperation: (OperationKind.None, IsInvalid) (Syntax: 'Case x')
Children(1):
ISingleValueCaseClause (CaseKind.SingleValue) (OperationKind.SingleValueCaseClause, IsInvalid) (Syntax: 'x')
Value: IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.Int32, IsInvalid) (Syntax: 'x')
ISingleValueCaseClause (CaseKind.SingleValue) (OperationKind.SingleValueCaseClause, IsInvalid) (Syntax: 'x')
Value: IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.Int32, IsInvalid) (Syntax: 'x')
]]>.Value
Dim expectedDiagnostics = <![CDATA[
......@@ -855,10 +853,7 @@ End Structure
references:={MscorlibRef, SystemRef, compilation0.EmitToImageReference(embedInteropTypes:=True)})
Dim expectedOperationTree = <![CDATA[
IInvalidExpression (OperationKind.InvalidExpression, Type: I, IsInvalid) (Syntax: 'New I(x)')
Children(2):
IParameterReferenceExpression: x (OperationKind.ParameterReferenceExpression, Type: System.Object, IsInvalid) (Syntax: 'x')
IOperation: (OperationKind.None, IsInvalid) (Syntax: 'New I(x)')
IOperation: (OperationKind.None, IsInvalid) (Syntax: 'New I(x)')
]]>.Value
Dim expectedDiagnostics = <![CDATA[
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册