Skip to content

cmd/compile: nil check stack reported at write instead of previous nil check #79762

@randall77

Description

@randall77
package main

type T struct {
	a int
}

func (t *T) foo() {
	t.a = 3
}

func main() {
	var t *T
	(*t).foo()
}

This should panic at the second line of main, not inside foo.

Good stack trace:

main.main()
	/Users/khr/tmp6.go:13 +0x8

Bad stack trace:

main.(*T).foo(...)
	/Users/khr/tmp6.go:8
main.main()
	/Users/khr/tmp6.go:13 +0xc

This looks like a regression in #33724. It was fine in 1.24.13, but broken in 1.25.0 and since.

A subtler case, where the dereference is implicit in the conversion from *T to *U:

type T struct {
	U
}
type U struct {
	x int
}

func (u *U) setX() {
	u.x = 7
}

func main() {
	var t *T
	t.setX()
}

Metadata

Metadata

Assignees

Labels

FixPendingIssues that have a fix which has not yet been reviewed or submitted.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type
No fields configured for issues without a type.

Projects

Status
In Progress

Relationships

None yet

Development

No branches or pull requests

Issue actions