Skip to content

Commit 4a095b8

Browse files
taylorzagriesemer
authored andcommitted
cmd/compile: don't crash reporting misuse of shadowed built-in function
The existing implementation causes a compiler panic if a function parameter shadows a built-in function, and then calling that shadowed name. Fixes #27356 Change-Id: I1ffb6dc01e63c7f499e5f6f75f77ce2318f35bcd Reviewed-on: https://go-review.googlesource.com/132876 Reviewed-by: Robert Griesemer <[email protected]> Run-TryBot: Robert Griesemer <[email protected]> TryBot-Result: Gobot Gobot <[email protected]>
1 parent 98fd668 commit 4a095b8

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

src/cmd/compile/internal/gc/typecheck.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ func typecheck1(n *Node, top int) *Node {
12631263
n.Op = OCALLFUNC
12641264
if t.Etype != TFUNC {
12651265
name := l.String()
1266-
if isBuiltinFuncName(name) {
1266+
if isBuiltinFuncName(name) && l.Name.Defn != nil {
12671267
// be more specific when the function
12681268
// name matches a predeclared function
12691269
yyerror("cannot call non-function %s (type %v), declared at %s",

test/fixedbugs/issue27356.go

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// errorcheck
2+
3+
// Copyright 2018 The Go Authors. All rights reserved.
4+
// Use of this source code is governed by a BSD-style
5+
// license that can be found in the LICENSE file.
6+
7+
// Issue 27356: function parameter hiding built-in function results in compiler crash
8+
9+
package p
10+
11+
var a = []int{1,2,3}
12+
13+
func _(len int) {
14+
_ = len(a) // ERROR "cannot call non-function"
15+
}
16+
17+
var cap = false
18+
var _ = cap(a) // ERROR "cannot call non-function"
19+

0 commit comments

Comments
 (0)