diff --git a/src/cmd/compile/internal/staticinit/sched.go b/src/cmd/compile/internal/staticinit/sched.go index 7317ed1fec4..91c0a27faf0 100644 --- a/src/cmd/compile/internal/staticinit/sched.go +++ b/src/cmd/compile/internal/staticinit/sched.go @@ -107,6 +107,20 @@ func (s *Schedule) tryStaticInit(n ir.Node) bool { case ir.OAS: n := n.(*ir.AssignStmt) lhs, rhs = []ir.Node{n.X}, n.Y + case ir.OAS2: + // Usually OAS2 has been rewritten to separate OASes by types2. + // What's left here is "var a, b = tmp1, tmp2" as a result from rewriting + // "var a, b = f()" that needs type conversion, which is not static. + n := n.(*ir.AssignListStmt) + for _, rhs := range n.Rhs { + for rhs.Op() == ir.OCONVNOP { + rhs = rhs.(*ir.ConvExpr).X + } + if name, ok := rhs.(*ir.Name); !ok || !name.AutoTemp() { + base.FatalfAt(n.Pos(), "unexpected rhs, not an autotmp: %+v", rhs) + } + } + return false case ir.OAS2DOTTYPE, ir.OAS2FUNC, ir.OAS2MAPR, ir.OAS2RECV: n := n.(*ir.AssignListStmt) if len(n.Lhs) < 2 || len(n.Rhs) != 1 { diff --git a/test/fixedbugs/issue68264.go b/test/fixedbugs/issue68264.go new file mode 100644 index 00000000000..7d67e55f6e4 --- /dev/null +++ b/test/fixedbugs/issue68264.go @@ -0,0 +1,15 @@ +// compile + +// Copyright 2024 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 p + +type nat []int + +var a, b nat = y() + +func y() (nat, []int) { + return nat{0}, nat{1} +}