Skip to content

cmd/go: go fix breaks code using //go:fix inline due to semantic conflict #79813

Description

@rsc
% cat x.go
package p

type Buf struct {
	s []int
}

var s S

type S struct {
	buf Buf
}

// del removes element i from p.s. Its body mentions the parameter p twice.
//
//go:fix inline
func del(p *Buf, i int) {
	p.s = append(p.s[:i], p.s[i+1:]...)
}

func (s *S) run() {
	// Two inlinable calls in the SAME block, both with the address-of-a-field
	// argument &s.buf.
	del(&s.buf, 0)
	del(&s.buf, 0)
}
% go build x.go
% go fix x.go
% go build x.go
# command-line-arguments
./x.go:25:6: p redeclared in this block
	./x.go:23:6: other declaration of p
% cat x.go
package p

type Buf struct {
	s []int
}

var s S

type S struct {
	buf Buf
}

// del removes element i from p.s. Its body mentions the parameter p twice.
//
//go:fix inline
func del(p *Buf, i int) {
	p.s = append(p.s[:i], p.s[i+1:]...)
}

func (s *S) run() {
	// Two inlinable calls in the SAME block, both with the address-of-a-field
	// argument &s.buf.
	var p *Buf = &s.buf
	p.s = append(p.s[:0], p.s[0+1:]...)
	var p *Buf = &s.buf
	p.s = append(p.s[:0], p.s[0+1:]...)
}

/cc @adonovan; tentatively marking release-blocker

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions