Skip to content

Commit

Permalink
eval,parser: allow padding fields in structs
Browse files Browse the repository at this point in the history
  • Loading branch information
sbinet committed Dec 21, 2017
1 parent 871855b commit 0d66a85
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
6 changes: 6 additions & 0 deletions eval/testdata/typedecl.ng
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@ type T8 struct {
B string "xml"
}

type Padding struct {
_ [4]byte
N string
_ [4]byte
}

print("OK")
2 changes: 1 addition & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,7 @@ func (p *Parser) maybeParseType() tipe.Type {
ftag = tipe.StructTag(str)
p.next()
}
if n != "" && tags[n] {
if n != "" && n != "_" && tags[n] {
p.errorf("field %s redeclared in struct %s", n, format.Type(s))
} else {
tags[n] = true
Expand Down
23 changes: 23 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,29 @@ var stmtTests = []stmtTest{
}}},
},
}},
{`type T struct {
_ [4]byte
N string
_ [4]byte
}`, &stmt.TypeDecl{
Name: "T",
Type: &tipe.Named{
Type: &tipe.Struct{Fields: []tipe.StructField{
{
Name: "_",
Type: &tipe.Array{Len: 4, Elem: &tipe.Unresolved{Name: "byte"}},
},
{
Name: "N",
Type: &tipe.Unresolved{Name: "string"},
},
{
Name: "_",
Type: &tipe.Array{Len: 4, Elem: &tipe.Unresolved{Name: "byte"}},
},
}},
},
}},
{
`type (
T int64
Expand Down

0 comments on commit 0d66a85

Please sign in to comment.