}
func declPos(decl *ir.Name) src.XPos {
- if decl.Defn != nil && (decl.Captured() || decl.Byval()) {
- // It's not clear which position is correct for captured variables here:
- // * decl.Pos is the wrong position for captured variables, in the inner
- // function, but it is the right position in the outer function.
- // * decl.Name.Defn is nil for captured variables that were arguments
- // on the outer function, however the decl.Pos for those seems to be
- // correct.
- // * decl.Name.Defn is the "wrong" thing for variables declared in the
- // header of a type switch, it's their position in the header, rather
- // than the position of the case statement. In principle this is the
- // right thing, but here we prefer the latter because it makes each
- // instance of the header variable local to the lexical block of its
- // case statement.
- // This code is probably wrong for type switch variables that are also
- // captured.
- return decl.Defn.Pos()
+ if decl.IsClosureVar() {
+ decl = decl.Defn.(*ir.Name)
}
return decl.Pos()
}