Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Panic when using short variable declaration in select...case #426

Closed
tweekmonster opened this issue Feb 20, 2017 · 3 comments
Closed

Panic when using short variable declaration in select...case #426

tweekmonster opened this issue Feb 20, 2017 · 3 comments
Labels

Comments

@tweekmonster
Copy link

Minimal reproduction:

package main

import "time"

func test() {
	t := time.NewTicker(time.Second)
	select {
	case _, ok := <-t.C:
		// Panics in here
	}
}

This works without panicking:

package main

import "time"

func test() {
	t := time.NewTicker(time.Second)
	var ok bool
	select {
	case _, ok = <-t.C:
		// No panic
	}
}

Debug log:

2017/02/20 10:08:02 Cursor at: 124
2017/02/20 10:08:02 -------------------------------------------------------
package main

import "time"

func test() {
        t := time.NewTicker(time.Second)
        select {
        case _, ok := <-t.C:
                // Panics in #here
        }
}
2017/02/20 10:08:02 -------------------------------------------------------
2017/02/20 10:08:02 Found "time" at "/home/tallen/.local/go/1.8/pkg/linux_amd64/time.a"
panic: runtime error: invalid memory address or nil pointer dereference
1(runtime.call32): /home/tallen/.local/go/1.8/src/runtime/asm_amd64.s:514
2(runtime.gopanic): /home/tallen/.local/go/1.8/src/runtime/panic.go:489
3(runtime.panicmem): /home/tallen/.local/go/1.8/src/runtime/panic.go:63
4(runtime.sigpanic): /home/tallen/.local/go/1.8/src/runtime/signal_unix.go:290
5(main.(*auto_complete_file).process_select_stmt): /home/tallen/.local/share/go/src/github.com/nsf/gocode/autocompletefile.go:246
6(main.(*auto_complete_file).process_stmt): /home/tallen/.local/share/go/src/github.com/nsf/gocode/autocompletefile.go:220
7(main.(*auto_complete_file).process_block_stmt): /home/tallen/.local/share/go/src/github.com/nsf/gocode/autocompletefile.go:159
8(main.(*auto_complete_file).process_decl_locals): /home/tallen/.local/share/go/src/github.com/nsf/gocode/autocompletefile.go:122
9(main.(*auto_complete_file).process_data): /home/tallen/.local/share/go/src/github.com/nsf/gocode/autocompletefile.go:106
10(main.(*auto_complete_context).apropos): /home/tallen/.local/share/go/src/github.com/nsf/gocode/autocompletecontext.go:298
11(main.server_auto_complete): /home/tallen/.local/share/go/src/github.com/nsf/gocode/server.go:202
12(main.(*RPC).RPC_auto_complete): /home/tallen/.local/share/go/src/github.com/nsf/gocode/rpc.go:26
13(runtime.call64): /home/tallen/.local/go/1.8/src/runtime/asm_amd64.s:515
14(reflect.Value.call): /home/tallen/.local/go/1.8/src/reflect/value.go:434
15(reflect.Value.Call): /home/tallen/.local/go/1.8/src/reflect/value.go:302
16(net/rpc.(*service).call): /home/tallen/.local/go/1.8/src/net/rpc/server.go:387
17(runtime.goexit): /home/tallen/.local/go/1.8/src/runtime/asm_amd64.s:2197
@nsf nsf added the Bug label Feb 20, 2017
@zchee
Copy link
Contributor

zchee commented Feb 25, 2017

@nsf I trying solve it.
It works and passes the test, but I'm not confident the correct fix. (really. just short development)
zchee@2ec8ad0
Edit: rebased

However, current master also can't get var ok bool variable candidates on following the sample code. (got onlyvar foo #time.Time)
But also solved it.

package main

import "time"

func test() {
	t := time.NewTicker(time.Second)
	select {
	case foo, ok := <-t.C:
		#
	}
}

If correct fix and you like it, I'll send a pull request.

@nsf
Copy link
Owner

nsf commented Feb 25, 2017

I'll take a look at this and other bugs tomorrow.

@nsf
Copy link
Owner

nsf commented Feb 26, 2017

You're right about missing ok bool, maybe one day I'll fix it. In the mean time I fixed the panic. Will open a separate issue for "ok" part here: #431

@nsf nsf closed this as completed Feb 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants