Skip to content
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

fmt: run doesn't panic, but debug panics when using embed object #65299

Closed
armstrongli opened this issue Jan 26, 2024 · 5 comments
Closed

fmt: run doesn't panic, but debug panics when using embed object #65299

armstrongli opened this issue Jan 26, 2024 · 5 comments
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.

Comments

@armstrongli
Copy link

armstrongli commented Jan 26, 2024

Go version

all go versions up to 1.21.6

Output of go env in your module/workspace:

GOARCH='amd64'
GOBIN='/Users/foo/gobin'
GOCACHE='/Users/foo/Library/Caches/go-build'
GOENV='/Users/foo/Library/Application Support/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='darwin'
GOINSECURE=''
GOMODCACHE='/Users/foo/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='darwin'
GOPATH='/Users/foo/go'
GOPRIVATE=''
GOPROXY=''
GOROOT='/Users/foo/go/go1.21.6'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/Users/foo/go/go1.21.6/pkg/tool/darwin_amd64'
GOVCS=''
GOVERSION='go1.21.6'
GOAMD64='v1'
GOMOD='/Users/foo/git/debug/go.mod'
GOWORK=''
GOGCCFLAGS='-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -ffile-prefix-map=/var/folders/dp/kz0kc_y54pd7v_g1t2wydhzr0000gq/T/go-build1338974926=/tmp/go-build -gno-record-gcc-switches -fno-common'

What did you do?

i run the following test case, and everything runs well. but when i debug, it panics.

func TestPrintDebugPanic(t *testing.T) {
	tt := (*Foo)(nil)
	fmt.Printf("%v", tt)
}

type Foo struct {
	Bar
}

type Bar struct{}

func (Bar) String() string {
	return "bar"
}

What did you see happen?

the UT can execute in Running mode, but panics in debug mode.

the if check on nil doesn't return true as it is a typed interface nil rather than the raw nil.

	if arg == nil { // <<< return false
		switch verb {
		case 'T', 'v':
			p.fmt.padString(nilAngleString)
		default:
			p.badVerb(verb)
		}
		return
	}

...


		switch verb {
		case 'v', 's', 'x', 'X', 'q':
			// Is it an error or Stringer?
			// The duplication in the bodies is necessary:
			// setting handled and deferring catchPanic
			// must happen before calling the method.
			switch v := p.arg.(type) {
			case error:
				handled = true
				defer p.catchPanic(p.arg, verb, "Error")
				p.fmtString(v.Error(), verb)
				return

			case Stringer:
				handled = true
				defer p.catchPanic(p.arg, verb, "String")
				p.fmtString(v.String(), verb) // <<<<< calls here because the embed Bar implmeent the String()string interface. v is nil
				return
			}
		}

What did you expect to see?

debug should run well and also print as running:

<nil>
@gopherbot
Copy link

Change https://go.dev/cl/558697 mentions this issue: fix unexpected panics on nil Type with embed type implementing String interface

@seankhliao
Copy link
Member

what's debug mode?

@cherrymui
Copy link
Member

Could you explain what are "Running mode" and "debug mode"? The Go toolchain and standard library don't have those mode.

If you're running in an IDE, it could be that the code panics and recovers, but the IDE's debugger captures the first panic and pauses the execution. If that is the case, you should be able to continue the execution and let it recover.

@cherrymui cherrymui added the WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided. label Jan 26, 2024
@aarzilli
Copy link
Contributor

As it turns out (go-delve/delve#3651) this is caused by a limitation of old versions of debugserver (go-delve/delve#852)

@armstrongli
Copy link
Author

@seankhliao

what's debug mode?

debug with delve.


@cherrymui

Could you explain what are "Running mode" and "debug mode"? The Go toolchain and standard library don't have those mode.

it's the debug with delve.


@aarzilli

As it turns out (go-delve/delve#3651) this is caused by a limitation of old versions of debugserver (go-delve/delve#852)

yes. that's correct. will update the xcode and have a try.


thank you all for the review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WaitingForInfo Issue is not actionable because of missing required information, which needs to be provided.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants