提交 f91f0a49 编写于 作者: C ChuckStoner

CallerLineNumber value was set to beginning of expression rather than method...

CallerLineNumber value was set to beginning of expression rather than method name (changeset 1355770)
上级 8619882a
......@@ -2974,7 +2974,7 @@ ProduceBoundNode:
Dim callerInfoValue As ConstantValue = Nothing
If isCallerLineNumber Then
callerInfoValue = ConstantValue.Create(callerInfoOpt.SyntaxTree.GetDisplayLineNumber(callerInfoOpt.Span))
callerInfoValue = ConstantValue.Create(callerInfoOpt.SyntaxTree.GetDisplayLineNumber(GetCallerLocation(callerInfoOpt)))
ElseIf isCallerMemberName Then
Dim container As Symbol = ContainingMember
......@@ -3118,6 +3118,16 @@ ProduceBoundNode:
Return defaultArgument
End Function
Private Shared Function GetCallerLocation(syntax As VBSyntaxNode) As TextSpan
Select Case syntax.Kind
Case SyntaxKind.SimpleMemberAccessExpression
Return DirectCast(syntax, MemberAccessExpressionSyntax).Name.Span
Case SyntaxKind.DictionaryAccessExpression
Return DirectCast(syntax, MemberAccessExpressionSyntax).OperatorToken.Span
Case Else
Return syntax.Span
End Select
End Function
''' <summary>
''' Return true if the node is an immediate child of a call statement.
......
......@@ -1814,6 +1814,141 @@ Void Main() - 10, Main, a.vb
CompileAndVerify(compilation, expectedOutput)
End Sub
<WorkItem(1040287)>
<Fact()>
Public Sub CallerInfo5()
Dim source =
<compilation>
<file name="a.vb">
<![CDATA[
Imports System
Imports System.Runtime.CompilerServices
Class C
ReadOnly Property P As C
Get
Return Me
End Get
End Property
Default ReadOnly Property Q(index As Integer, <CallerLineNumber> Optional line As Integer = 0) As C
Get
Console.WriteLine("{0}: {1}", index, line)
Return Me
End Get
End Property
Function F(Optional id As Integer = 0, <CallerLineNumber> Optional line As Integer = 0) As C
Console.WriteLine("{0}: {1}", id, line)
Return Me
End Function
Shared Sub Main()
Dim c = New C()
c.F(1).
F
c = c(
2
)(3)
c = c.
F(
4
).
P(5)
Dim o As Object = c
o =
DirectCast(o, C)(
6
)
End Sub
End Class
]]>
</file>
</compilation>
Dim compilation = CreateCompilationWithMscorlib45AndVBRuntimeAndReferences(source, options:=TestOptions.ReleaseExe)
CompileAndVerify(compilation,
<![CDATA[
1: 21
0: 22
2: 23
3: 23
4: 27
5: 30
6: 33
]]>)
End Sub
<WorkItem(1040287)>
<Fact()>
Public Sub CallerInfo6()
Dim source =
<compilation>
<file name="a.vb">
<![CDATA[
Imports System
Imports System.Runtime.CompilerServices
Class C
Function F() As C
Return Me
End Function
Default ReadOnly Property P(s As String, <CallerLineNumber> Optional line As Integer = 0) As C
Get
Console.WriteLine("{0}: {1}", s, line)
Return Me
End Get
End Property
Shared Sub Main()
Dim c = (New C())!x.
F()!y
End Sub
End Class
]]>
</file>
</compilation>
Dim compilation = CreateCompilationWithMscorlib45AndVBRuntimeAndReferences(source, options:=TestOptions.ReleaseExe)
CompileAndVerify(compilation,
<![CDATA[
x: 14
y: 15
]]>)
End Sub
<Fact()>
Public Sub CallerInfo7()
Dim compilation1 = CreateCSharpCompilation(<![CDATA[
using System.Runtime.CompilerServices;
public delegate void D(object o = null, [CallerLineNumber]int line = 0);
]]>.Value,
assemblyName:="1",
referencedAssemblies:=New MetadataReference() {MscorlibRef_v4_0_30316_17626})
compilation1.VerifyDiagnostics()
Dim reference1 = MetadataReference.CreateFromImage(compilation1.EmitToArray())
Dim compilation2 = CreateCompilationWithMscorlib45AndVBRuntimeAndReferences(
<compilation>
<file name="a.vb">
<![CDATA[
Imports System
Imports System.Runtime.CompilerServices
Class C
Shared Sub M(Optional o As Object = Nothing, <CallerLineNumber> Optional line As Integer = 0)
Console.WriteLine(line)
End Sub
Shared Sub Main()
Dim d As New D(AddressOf M)
d(
1
)
d
End Sub
End Class
]]>
</file>
</compilation>,
options:=TestOptions.ReleaseExe,
additionalRefs:={reference1})
CompileAndVerify(compilation2,
<![CDATA[
9
12
]]>)
End Sub
<Fact>
Public Sub TestCallerFilePath1()
Dim source1 = "
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册