delve icon indicating copy to clipboard operation
delve copied to clipboard

Wrong declLine inside a closure

Open nd opened this issue 6 years ago • 1 comments
trafficstars

  1. What version of Delve are you using (dlv version)?
Delve Debugger
Version: 1.2.0
Build: 4779218a8354d2facdbf2c48263c4144be330ca0
  1. What version of Go are you using? (go version)?
go version go1.12.9 linux/386
  1. What operating system and processor architecture are you using?
Linux, x86_64
  1. What did you do?

Debugged the following program with a breakpoint at line 8

package main

func main() {
	v := 1
	closure := func() {
		println(v)
		v := 2
		println(v) //break
	}
	closure()
	println(v)
}

Executed the locals command when debugger reaches the breakpoint.

  1. What did you expect to see?

The v=1 defined outside of the closure has DeclLine = 4.

  1. What did you see instead?

The v=1 defined outside of the closure has DeclLine = 6.

Full log: https://gist.github.com/nd/5fa605ac3e24fa42b35c7dc448998a5e.

nd avatar Aug 16 '19 08:08 nd

This is a compiler bug, and it's compilcated, see $GOROOT/src/cmd/compile/internal/gc/pgen.go:425

aarzilli avatar Aug 17 '19 07:08 aarzilli