Join GitHub today
spec: empty vs absent struct field tag #15412
Go spec says
What does it mean for tags to be identical? In particular, is an absent tag identical to an empty tag?
cmd/compile rejects this code, but gotype and gccgo-4.8 accept it:
Package reflect's StructField doesn't provide a way to distinguish absent from empty tags, but then it also agrees with cmd/compile that the above types are not assignable to each other: http://play.golang.org/p/QNISntvhWb
My 2c: We should treat empty and absent tags as identical. Package reflect's current API makes it difficult to extend to support distinguishing them: we can't add new fields to
There also seems to be little value in distinguishing them. The conventional usage of struct tags involve key-value pairs, for which empty and absent tags can be treated identically anyway.
Actually, the spec is already clear: See http://tip.golang.org/ref/spec#Struct_types, first example:
Comment on first fields: an empty tag string is like an absent tag
I'll add an additional sentence to the prose.