diff --git a/Src/Compilers/VisualBasic/Portable/Binding/Binder_Invocation.vb b/Src/Compilers/VisualBasic/Portable/Binding/Binder_Invocation.vb index 0d319fa7056935ec87219014dd79f07d314eb91a..406de91acc21b6d4625ba36b688d8f27d44db17d 100644 --- a/Src/Compilers/VisualBasic/Portable/Binding/Binder_Invocation.vb +++ b/Src/Compilers/VisualBasic/Portable/Binding/Binder_Invocation.vb @@ -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 ''' ''' Return true if the node is an immediate child of a call statement. diff --git a/Src/Compilers/VisualBasic/Test/Semantic/Semantics/OptionalArgumentTests.vb b/Src/Compilers/VisualBasic/Test/Semantic/Semantics/OptionalArgumentTests.vb index f94ba35f2b4b7f3bfd696fb578fa2fe7cdf68647..d6d2bd5021a7636988f80eff2566db8e31dac6d1 100644 --- a/Src/Compilers/VisualBasic/Test/Semantic/Semantics/OptionalArgumentTests.vb +++ b/Src/Compilers/VisualBasic/Test/Semantic/Semantics/OptionalArgumentTests.vb @@ -1814,6 +1814,141 @@ Void Main() - 10, Main, a.vb CompileAndVerify(compilation, expectedOutput) End Sub + + + Public Sub CallerInfo5() + Dim source = + + + 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, 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 + ]]> + + + Dim compilation = CreateCompilationWithMscorlib45AndVBRuntimeAndReferences(source, options:=TestOptions.ReleaseExe) + CompileAndVerify(compilation, + ) + End Sub + + + + Public Sub CallerInfo6() + Dim source = + + + 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 + ]]> + + + Dim compilation = CreateCompilationWithMscorlib45AndVBRuntimeAndReferences(source, options:=TestOptions.ReleaseExe) + CompileAndVerify(compilation, + ) + End Sub + + + Public Sub CallerInfo7() + Dim compilation1 = CreateCSharpCompilation(.Value, + assemblyName:="1", + referencedAssemblies:=New MetadataReference() {MscorlibRef_v4_0_30316_17626}) + compilation1.VerifyDiagnostics() + Dim reference1 = MetadataReference.CreateFromImage(compilation1.EmitToArray()) + Dim compilation2 = CreateCompilationWithMscorlib45AndVBRuntimeAndReferences( + + + 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 + ]]> + + , + options:=TestOptions.ReleaseExe, + additionalRefs:={reference1}) + CompileAndVerify(compilation2, + ) + End Sub + Public Sub TestCallerFilePath1() Dim source1 = "