]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/compile: prevent irgen crashing for empty local declaration stmt
authorCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 16 Nov 2021 14:59:15 +0000 (21:59 +0700)
committerCuong Manh Le <cuong.manhle.vn@gmail.com>
Tue, 16 Nov 2021 15:38:59 +0000 (15:38 +0000)
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>
src/cmd/compile/internal/noder/stmt.go
test/fixedbugs/issue49611.go [new file with mode: 0644]
test/typeparam/issue49611.go [new file with mode: 0644]

index e329a591566ce4657a7bea6cc0d4dfc441d6c1b6..1e996b95c48ffa506d61573f7bde134cc80be639 100644 (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)
diff --git a/test/fixedbugs/issue49611.go b/test/fixedbugs/issue49611.go
new file mode 100644 (file)
index 0000000..b40ad58
--- /dev/null
@@ -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 ()
+}
diff --git a/test/typeparam/issue49611.go b/test/typeparam/issue49611.go
new file mode 100644 (file)
index 0000000..96c651e
--- /dev/null
@@ -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 ()
+}