Skip to content

cmd/fix, x/tools/internal/refactor/inline: inlining a generic may turn non-constant len/cap/unsafe.Sizeof exprs into constants, changing semantics and/or validity #78169

@zigo101

Description

@zigo101

Go version

go version go1.26.1 linux/amd64

Output of go env in your module/workspace:

.

What did you do?

Case 1:

package main

//go:fix inline
func foo[T [8]byte | [4]uint16]() {
    var v T
    var n byte = 1 << len(v) >> len(v)
    if n == 0 {
        println("T is [8]byte")
    } else {
        println("T is [4]uint16]")
    }
}

func main() {
    foo[[8]byte]()
}

Case 2:

package main

import "unsafe"

//go:fix inline
func foo[T any]() {
    var t T
    _ = 1 / unsafe.Sizeof(t)
}

func main() {
    foo[struct{}]()
}

What did you see happen?

Code behavior changes.

What did you expect to see?

Not change code behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugReportIssues describing a possible bug in the Go implementation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions