Skip to content

runtime.Caller() return wrong number of line #663

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
gopherbot opened this issue Mar 12, 2010 · 1 comment
Closed

runtime.Caller() return wrong number of line #663

gopherbot opened this issue Mar 12, 2010 · 1 comment

Comments

@gopherbot
Copy link
Contributor

by izmalych:

What steps will reproduce the problem?

main.go:
package main

import (
        "fmt";
        "runtime";
        )

func main() {
        log("line # 9")
        fmt.Println("line # 10")
        log("line # 11")
        fmt.Println("line # 12")
}


func log(message string){
        _, file, line, ok := runtime.Caller(1)
        if !ok { fmt.Println("some error"); return }
        fmt.Printf("%s:%d %s\n", file, line, message)
}

What is the expected output?
./main.out
/home/alexni/workspace/go/test/main.go:9 line # 9
line # 10
/home/alexni/workspace/go/test/main.go:11 line # 11
line # 12

What do you see instead?
./main.out
/home/alexni/workspace/go/test/main.go:10 line # 9
line # 10                            ^^^^      
/home/alexni/workspace/go/test/main.go:12 line # 11
line # 12                            ^^^^


What is your $GOOS?  $GOARCH?
GOARCH=amd64
GOOS=linux




Which revision are you using?  (hg identify)

2dc7f4773836 tip

6g version 5040
@robpike
Copy link
Contributor

robpike commented Apr 6, 2010

Comment 1:

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants