courajs
(Aaron Sikes)
1
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?
calmh
(Jakob Borg)
2
Yep. The quoted bit defines a Type
but the example is a TypeDecl
described in another section - follow the link above the example.
courajs
(Aaron Sikes)
3
Oh, yep, makes sense. Thanks! So the purpose of parentheses is for grouping, maybe disambiguation?
calmh
(Jakob Borg)
4
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.
system
(system)
Closed
5
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.