Skip to content

cmd/compile: loopvar doesn't trigger nocopy detection #66070

@zigo101

Description

@zigo101

Go version

go version go1.22.0 linux/amd64

Output of go env in your module/workspace:

.

What did you do?

package main

import (
	"fmt"
	"strings"
)

func foo() string {
	for b, i := (strings.Builder{}), byte('a'); ; i++ {
		b.WriteByte(i)
		if i == 'z' {
			return b.String()
		}
	}
}

func bar(callback func(*strings.Builder)) string {
	for b, i := (strings.Builder{}), byte('a'); ; i++ {
		b.WriteByte(i)
		callback(&b) // <-- difference here
		if i == 'z' {
			return b.String()
		}
	}
}

func main() {
	debugProcess := func(pb *strings.Builder) {
		// do nothing
	}
	fmt.Println("foo:", foo())
	fmt.Println("bar:", bar(debugProcess))
}

What did you see happen?

Consistent behavior between foo and bar with 1.22 compiler.

What did you expect to see?

Inconsistent behavior between foo and bar with 1.22 compiler.

Metadata

Metadata

Assignees

Labels

NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

Type

No type

Projects

Status

In Progress

Relationships

None yet

Development

No branches or pull requests

Issue actions