According to the Go documentation a semicolon is optional if it is just before a )
or }
.
To allow complex statements to occupy a single line, a semicolon may be omitted before a closing ")" or "}".
I understand how the }
rule allows one liners such as the following:
if x { return 1 }
But what is the purpose of the )
rule? What kind of statement or other semicolon thing can appear just before a close parenthesis?
CodePudding user response:
To find where semicolons can appear before a closing parenthesis,
search the specification for the text ";" } ")"
.
Examples:
import ( "fmt"; )
var ( v int; )
const ( c = 1; )
type ( t []int; )