Skip to content

runtime: runtime.Caller() => "<autogenerated>" #16723

Closed
@thockin

Description

@thockin

I was playing with a method that wants to print the file:line of the caller. runtime.Caller(1) seems like it should do the trick, but I get ':2'. If I call runtime.Caller(2) instead it seems to work, but I am reluctant to depend on that.

It looks like this has to do with being an interface method: https://play.golang.org/p/I5XPdWR_O0

Is there a generic way to get the actual caller, safely, in all cases?


  1. What version of Go are you using (go version)?

go version go1.6.1 linux/amd64

  1. What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/thockin/src/go"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GO15VENDOREXPERIMENT="1"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0"
CXX="g++"
CGO_ENABLED="1"

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.early-in-cycleA change that should be done early in the 3 month dev cycle.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions