Definition of Type in the language spec seems wrong?

https://golang.org/ref/spec#Types

Here’s the formal definition for Type:
Type = TypeName | TypeLit | "(" Type ")" .

But here’s an example later:
type (
B1 string
B2 B1
B3 []B1
B4 B3
)

Seems to me that to allow multiple types between the parentheses, the definition should instead be:
Type = TypeName | TypeLit | "(" { Type } ")" .

Am I misunderstanding?

Yep. The quoted bit defines a Type but the example is a TypeDecl described in another section - follow the link above the example.

Oh, yep, makes sense. Thanks! So the purpose of parentheses is for grouping, maybe disambiguation?

Yeah… though I struggle to come up with a good example. For example, type foo [](*int) is valid but unnecessary.

We need parenthesis around the type when converting or type asserting but the parenthesis are part of the conversion / assertion expression.

I’m not sure when we need parenthesis just to express a type.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.