diff --git a/src/cmd/compile/internal/walk/range.go b/src/cmd/compile/internal/walk/range.go index a1e5442a69..3d3547b84b 100644 --- a/src/cmd/compile/internal/walk/range.go +++ b/src/cmd/compile/internal/walk/range.go @@ -605,7 +605,7 @@ func arrayClear(wbPos src.XPos, a ir.Node, nrange *ir.RangeStmt) ir.Node { // For array range clear, also set "i = len(a) - 1" if nrange != nil { - idx := ir.NewAssignStmt(base.Pos, nrange.Key, ir.NewBinaryExpr(base.Pos, ir.OSUB, ir.NewUnaryExpr(base.Pos, ir.OLEN, a), ir.NewInt(base.Pos, 1))) + idx := ir.NewAssignStmt(base.Pos, nrange.Key, typecheck.Conv(ir.NewBinaryExpr(base.Pos, ir.OSUB, ir.NewUnaryExpr(base.Pos, ir.OLEN, a), ir.NewInt(base.Pos, 1)), nrange.Key.Type())) n.Body.Append(idx) } diff --git a/test/fixedbugs/issue73491.go b/test/fixedbugs/issue73491.go new file mode 100644 index 0000000000..4137088bde --- /dev/null +++ b/test/fixedbugs/issue73491.go @@ -0,0 +1,25 @@ +// build + +// Copyright 2025 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package main + +type T int + +const K T = 5 + +type P struct { + a [K]*byte +} + +//go:noinline +func f(p *P) { + for i := range K { + p.a[i] = nil + } +} +func main() { + f(nil) +}