cmd/cgo: fix line number in an error message

Fixes #6563.

R=golang-dev, iant
CC=golang-dev
https://golang.org/cl/14870046
This commit is contained in:
Russ Cox 2013-10-18 16:52:44 -04:00
parent 06ad3b2de1
commit dbe2eacf04
4 changed files with 54 additions and 15 deletions

View file

@ -654,7 +654,7 @@ func (p *Package) rewriteRef(f *File) {
// Okay - might be new(T)
expr = r.Name.Type.Go
} else if r.Name.Kind == "var" {
expr = &ast.StarExpr{X: expr}
expr = &ast.StarExpr{Star: (*r.Expr).Pos(), X: expr}
}
case "type":
@ -683,6 +683,16 @@ func (p *Package) rewriteRef(f *File) {
}
}
}
// Copy position information from old expr into new expr,
// in case expression being replaced is first on line.
// See golang.org/issue/6563.
pos := (*r.Expr).Pos()
switch x := expr.(type) {
case *ast.Ident:
expr = &ast.Ident{NamePos: pos, Name: x.Name}
}
*r.Expr = expr
}