Skip to content
This repository has been archived by the owner on May 9, 2021. It is now read-only.

"If block ends with a return ... " in chain of else ifs #290

Closed
200sc opened this issue Apr 28, 2017 · 1 comment
Closed

"If block ends with a return ... " in chain of else ifs #290

200sc opened this issue Apr 28, 2017 · 1 comment

Comments

@200sc
Copy link

200sc commented Apr 28, 2017

In this code:

func golintTest() {
	r := 0
	if r == 0 {
		r = 5
	} else if r == 3 {
		r = 2
	} else if r == 2 {
		r = -2
		return
	} else {
		panic("something invalid")
	}
        fmt.Println(r)
}

(Yes the actions going on are meaningless)

In this case, golint will suggest that we drop the else as the last 'else if' case returns.
That seems incorrect, if an earlier branch was taken.

Interestingly this will not happen if there is a single else if case with a return, and it
also won't happen if we add a third else if case before the return case.

@200sc
Copy link
Author

200sc commented Apr 28, 2017

Sorry, looks like this has been issued before and is in progress? #181

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant