未验证 提交 9619d5ec 编写于 作者: M Manish Vasani 提交者: GitHub

Merge pull request #23036 from mavasani/GetStandaloneNode

Do not invoke GetStandaloneNode helper in GetOperationWorker
......@@ -163,9 +163,6 @@ internal override Binder GetEnclosingBinderInternal(int position)
internal override IOperation GetOperationWorker(CSharpSyntaxNode node, CancellationToken cancellationToken)
{
// in case this is right side of a qualified name or member access (or part of a cref)
node = SyntaxFactory.GetStandaloneNode(node);
var model = this.GetMemberModel(node);
if (model != null)
{
......
......@@ -159,5 +159,45 @@ public void TestParentOperations()
VerifyParentOperations(model);
}
[CompilerTrait(CompilerFeature.IOperation)]
[WorkItem(23001, "https://github.com/dotnet/roslyn/issues/23001")]
[Fact]
public void TestGetOperationForQualifiedName()
{
var text = @"using System;
public class Test
{
class A
{
public B b;
}
class B
{
}
void M(A a)
{
int x2 = /*<bind>*/a.b/*</bind>*/;
}
}
";
var comp = CreateStandardCompilation(text, parseOptions: TestOptions.RegularWithIOperationFeature);
var tree = comp.SyntaxTrees.Single();
var model = comp.GetSemanticModel(tree);
// Verify we return non-null operation only for topmost member access expression.
var expr = (MemberAccessExpressionSyntax)GetExprSyntaxForBinding(GetExprSyntaxList(tree));
Assert.Equal("a.b", expr.ToString());
var operation = model.GetOperation(expr);
Assert.NotNull(operation);
Assert.Equal(OperationKind.FieldReference, operation.Kind);
var fieldOperation = (IFieldReferenceOperation)operation;
Assert.Equal("b", fieldOperation.Field.Name);
// Verify we return null operation for child nodes of member access expression.
Assert.Null(model.GetOperation(expr.Name));
}
}
}
......@@ -834,5 +834,39 @@ IAnonymousFunctionOperation (Symbol: Sub ()) (OperationKind.AnonymousFunction, T
VerifyOperationTreeAndDiagnosticsForTest(Of MultiLineLambdaExpressionSyntax)(source, expectedOperationTree, expectedDiagnostics)
End Sub
<CompilerTrait(CompilerFeature.IOperation)>
<Fact, WorkItem(23001, "https://github.com/dotnet/roslyn/issues/23001")>
Public Sub TestGetOperationForQualifiedName()
Dim source = <![CDATA[
Public Class Test
Private Class A
Public b As B
End Class
Private Class B
End Class
Private Sub M(a As A)
Dim x2 As Integer = a.b'BIND:"a.b"
End Sub
End Class
]]>.Value
Dim comp = CreateVisualBasicCompilation(source, parseOptions:=TestOptions.RegularWithIOperationFeature)
Dim tree = comp.SyntaxTrees.Single()
Dim model = comp.GetSemanticModel(tree)
' Verify we return non-null operation only for topmost member access expression.
Dim expr = CompilationUtils.FindBindingText(Of MemberAccessExpressionSyntax)(comp, tree.FilePath)
Assert.Equal("a.b", expr.ToString())
Dim operation = model.GetOperation(expr)
Assert.NotNull(operation)
Assert.Equal(OperationKind.FieldReference, operation.Kind)
Dim fieldOperation = DirectCast(operation, IFieldReferenceOperation)
Assert.Equal("b", fieldOperation.Field.Name)
' Verify we return null operation for child nodes of member access expression.
Assert.Null(model.GetOperation(expr.Name))
End Sub
End Class
End Namespace
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册