Closed
Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
Tested with GO 1.11
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (go env
)?
Compiling on Windows, reproduced targeting both Windows and Linux
What did you do?
NOTE: This does not reproduce on play.golang.org, but I have reproduced it on 3 different machines
If a function argument hides a built-in function and there is an attempt to call the built-in function the compiler will crash with no indication of where it was in the compilation process, which makes it hard to find in a large codebase.
Here is a simple repo of the issue
package main
var a = []byte{1,2,3}
func bug(len int) bool {
return len < len(a)
}
func main() {
println(bug(5))
}
Here the argument len hides the built-in function len, and in that same function a call is made to the function len.
What did you expect to see?
Compiler Error : cannot call non-function len (type int)
What did you see instead?
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xc0000005 code=0x0 addr=0x70 pc=0xb94675]
goroutine 1 [running]:
cmd/compile/internal/gc.typecheck1(0xc000352580, 0x2, 0xc00033fa40)
c:/go/src/cmd/compile/internal/gc/typecheck.go:1270 +0x3ed5
cmd/compile/internal/gc.typecheck(0xc000352580, 0x2, 0xc00033fa40)
c:/go/src/cmd/compile/internal/gc/typecheck.go:238 +0x6b4
cmd/compile/internal/gc.typecheck1(0xc000352600, 0x12, 0xc000084998)
c:/go/src/cmd/compile/internal/gc/typecheck.go:585 +0x2cce
cmd/compile/internal/gc.typecheck(0xc000352600, 0x12, 0xc0000849d8)
c:/go/src/cmd/compile/internal/gc/typecheck.go:238 +0x6b4
cmd/compile/internal/gc.typecheckslice(0xc0000885d0, 0x1, 0x1, 0x12)
c:/go/src/cmd/compile/internal/gc/typecheck.go:68 +0x57
cmd/compile/internal/gc.typecheck1(0xc000352680, 0x1, 0xcbf373)
c:/go/src/cmd/compile/internal/gc/typecheck.go:2065 +0xadd4
cmd/compile/internal/gc.typecheck(0xc000352680, 0x1, 0x3)
c:/go/src/cmd/compile/internal/gc/typecheck.go:238 +0x6b4
cmd/compile/internal/gc.typecheckslice(0xc0000885d8, 0x1, 0x1, 0x1)
c:/go/src/cmd/compile/internal/gc/typecheck.go:68 +0x57
cmd/compile/internal/gc.Main(0xcdea30)
c:/go/src/cmd/compile/internal/gc/main.go:518 +0x20d0
main.main()
c:/go/src/cmd/compile/main.go:51 +0x9d
Metadata
Metadata
Assignees
Type
Projects
Relationships
Development
No branches or pull requests
Activity
cherrymui commentedon Aug 30, 2018
It reports the error correctly with Go 1.10. Looks like a regression.
[-]Compiler Bug: function argument hiding built-in function results in a compiler crash[/-][+]cmd/compile: function argument hiding built-in function results in a compiler crash[/+]cherrymui commentedon Aug 30, 2018
cc @griesemer @mdempsky
FiloSottile commentedon Aug 30, 2018
@gopherbot please file this to be considered for backport to 1.11. This is a regression.
gopherbot commentedon Aug 30, 2018
Backport issue(s) opened: #27399 (for 1.11).
Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://golang.org/wiki/MinorReleases.
gopherbot commentedon Sep 2, 2018
Change https://golang.org/cl/132876 mentions this issue:
cmd/compile/internal/gc/typecheck : Added check to ensure that Node.Name.Defn is not nil before dereferencing. If it is nil we revert to the pre-1.11 error reporting.
gopherbot commentedon Oct 3, 2018
Change https://golang.org/cl/139103 mentions this issue:
[release-branch.go1.11] cmd/compile: don't crash reporting misuse of shadowed built-in function
[release-branch.go1.11] cmd/compile: don't crash reporting misuse of …
go1.11.2 updates tracking (#2)