mirror of
https://github.com/reactos/syzkaller.git
synced 2025-02-20 03:21:26 +00:00
pkg/compiler: detect duplicate fields in template structs
This commit is contained in:
parent
256b70f9cf
commit
90c54c496b
@ -137,9 +137,11 @@ func (comp *compiler) checkFields() {
|
||||
switch n := decl.(type) {
|
||||
case *ast.Struct:
|
||||
_, typ, name := n.Info()
|
||||
comp.checkFieldGroup(n.Fields, "field", typ+" "+name)
|
||||
if len(n.Fields) < 1 {
|
||||
comp.error(n.Pos, "%v %v has no fields, need at least 1 field", typ, name)
|
||||
comp.checkStructFields(n, typ, name)
|
||||
case *ast.TypeDef:
|
||||
if n.Struct != nil {
|
||||
_, typ, _ := n.Struct.Info()
|
||||
comp.checkStructFields(n.Struct, "template "+typ, n.Name.Name)
|
||||
}
|
||||
case *ast.Call:
|
||||
name := n.Name.Name
|
||||
@ -152,6 +154,13 @@ func (comp *compiler) checkFields() {
|
||||
}
|
||||
}
|
||||
|
||||
func (comp *compiler) checkStructFields(n *ast.Struct, typ, name string) {
|
||||
comp.checkFieldGroup(n.Fields, "field", typ+" "+name)
|
||||
if len(n.Fields) < 1 {
|
||||
comp.error(n.Pos, "%v %v has no fields, need at least 1 field", typ, name)
|
||||
}
|
||||
}
|
||||
|
||||
func (comp *compiler) checkFieldGroup(fields []*ast.Field, what, ctx string) {
|
||||
existing := make(map[string]bool)
|
||||
for _, f := range fields {
|
||||
|
1
pkg/compiler/testdata/errors.txt
vendored
1
pkg/compiler/testdata/errors.txt
vendored
@ -288,6 +288,7 @@ type templ_struct0[A, B] {
|
||||
|
||||
type templ_struct1[STR] {
|
||||
f string[STR, 40]
|
||||
f int32 ### duplicate field f in template struct templ_struct1
|
||||
}
|
||||
|
||||
type templ_struct2[A] {
|
||||
|
Loading…
x
Reference in New Issue
Block a user