Skip to content

cmd/compile: function argument hiding built-in function results in a compiler crash #27356

@taylorza

Description

@taylorza

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

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions