Go Short Variable Declaration Invalid Cases: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
(Created page with "=Internal= * Lexical Structure =With =")
 
No edit summary
 
(3 intermediate revisions by the same user not shown)
Line 3: Line 3:
* [[Go_Concepts_-_Lexical_Structure#Short_Variable_Declaration|Lexical Structure]]
* [[Go_Concepts_-_Lexical_Structure#Short_Variable_Declaration|Lexical Structure]]


=With =
=With Package-Level Variables=
 
<font color=red>'''TODO'''</font>
 
=With Method Receivers' Fields=
 
<pre>
...
 
type A struct {
    i int
}
 
func (a A) m(i int) {
    a.i := i + 1 // invalid
}
 
...
</pre>
 
Compiler error:
 
<pre>
./main.go:12: non-name a.i on left side of :=
</pre>

Latest revision as of 10:59, 4 April 2016

Internal

With Package-Level Variables

TODO

With Method Receivers' Fields

...

type A struct {
    i int
}

func (a A) m(i int) {
    a.i := i + 1 // invalid
}

...

Compiler error:

./main.go:12: non-name a.i on left side of :=