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" and it contains a "
SimpleStatement". The "SimpleStatement" contains the same "
Assignment" 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