Giving these 2 statements (in main function), the first passes and the
second causes a parse-error.
type T struct{}
func (T) F() bool { return true }
func main() {
v := T{}.F() // works
if v := T{}.F(); v {} // syntax error: cannot use v := T as value
}
I went over the grammar rules of the "If Statement
<https://golang.org/ref/spec#If_statements>" and it contains a "
SimpleStatement <https://golang.org/ref/spec#SimpleStmt>". The
"SimpleStatement" contains the same "Assignment
<https://golang.org/ref/spec#Assignments>" rule that is used for general
assignments. The first works, but the second fails. Any thoughts what's the
difference between the 2 assignments?
I can overcome this by just using "if v := (T{}).F()", but curious to know
the reason.
Thanks
--
You received this message because you are subscribed to the Google Groups
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/55cfc01d-376d-4cf9-83c4-be9b13380ea8n%40googlegroups.com.