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

Erroneous compiler error "function ends without a return statement" with if/else #2034

Closed
gopherbot opened this issue Jul 2, 2011 · 1 comment

Comments

@gopherbot
Copy link
Contributor

by [email protected]:

What steps will reproduce the problem?
<code>
package foo

import (
)

func StrArray() []string {                                                      
  if true {                                                                     
    return make([]string, 3)                                                    
  } else {                                                                      
    return nil                                                                  
  }                                                                             
}                                                                               
</code>
$ 6g foo.go
foo.go:6: function ends without a return statement


What is the expected output?

Should compile.  The following code compiles just fine:
<code>
package foo

import (
)

func StrArray() []string {                                                      
  if true {                                                                     
    return make([]string, 3)                                                    
  }
  return nil                                                                  
}                                                                               
</code>

What do you see instead?
Compilation failed

Which compiler are you using (5g, 6g, 8g, gccgo)?
6g

Which operating system are you using?
linux

Which revision are you using?  (hg identify)
$ hg identify
13ec466f6670 tip
@robpike
Copy link
Contributor

robpike commented Jul 3, 2011

Comment 1:

Status changed to Duplicate.

Merged into issue #65.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants