1
0
mirror of https://github.com/golang/go synced 2024-11-11 19:51:37 -07:00

cmd/compile: prevent irgen crashing for empty local declaration stmt

Updates #47631
Fixes #49611

Change-Id: Ib4a4466038e0d4a9aa9380d7909f29f7d15c6c69
Reviewed-on: https://go-review.googlesource.com/c/go/+/364314
Trust: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Run-TryBot: Cuong Manh Le <cuong.manhle.vn@gmail.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
This commit is contained in:
Cuong Manh Le 2021-11-16 21:59:15 +07:00
parent 7c50ef6c8c
commit 7f4a946fa2
3 changed files with 27 additions and 3 deletions

View File

@ -46,9 +46,11 @@ func (g *irgen) stmt(stmt syntax.Stmt) ir.Node {
n.SetTypecheck(1)
return n
case *syntax.DeclStmt:
if _, ok := stmt.DeclList[0].(*syntax.TypeDecl); ok && g.topFuncIsGeneric {
// TODO: remove this restriction. See issue 47631.
base.ErrorfAt(g.pos(stmt), "type declarations inside generic functions are not currently supported")
if g.topFuncIsGeneric && len(stmt.DeclList) > 0 {
if _, ok := stmt.DeclList[0].(*syntax.TypeDecl); ok {
// TODO: remove this restriction. See issue 47631.
base.ErrorfAt(g.pos(stmt), "type declarations inside generic functions are not currently supported")
}
}
n := ir.NewBlockStmt(g.pos(stmt), nil)
g.decls(&n.List, stmt.DeclList)

View File

@ -0,0 +1,11 @@
// compile
// Copyright 2021 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
func f() {
var ()
}

View File

@ -0,0 +1,11 @@
// compile -G=3
// Copyright 2021 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
func f[T any]() {
var ()
}