Skip to content

Commit

Permalink
cl: toStructType check name redeclared
Browse files Browse the repository at this point in the history
  • Loading branch information
visualfc committed Jan 20, 2022
1 parent f6c9f19 commit 27e36c0
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion cl/func_type_and_var.go
Original file line number Diff line number Diff line change
Expand Up @@ -209,15 +209,33 @@ func toStructType(ctx *blockCtx, v *ast.StructType) *types.Struct {
fieldList := v.Fields.List
fields := make([]*types.Var, 0, len(fieldList))
tags := make([]string, 0, len(fieldList))
names := make(map[string]token.Pos)
chkRedecl := func(name string, pos token.Pos) bool {
if opos, ok := names[name]; ok {
npos := ctx.Position(pos)
ctx.handleCodeErrorf(&npos, "%v redeclared\n\t%v other declaration of %v",
name, ctx.Position(opos), name)
return true
}
names[name] = pos
return false
}
for _, field := range fieldList {
typ := toType(ctx, field.Type)
if field.Names == nil { // embedded
fld := types.NewField(token.NoPos, pkg, getTypeName(typ), typ, true)
name := getTypeName(typ)
if chkRedecl(name, field.Type.Pos()) {
continue
}
fld := types.NewField(token.NoPos, pkg, name, typ, true)
fields = append(fields, fld)
tags = append(tags, toFieldTag(field.Tag))
continue
}
for _, name := range field.Names {
if chkRedecl(name.Name, name.NamePos) {
continue
}
fld := types.NewField(token.NoPos, pkg, name.Name, typ, false)
fields = append(fields, fld)
tags = append(tags, toFieldTag(field.Tag))
Expand Down

0 comments on commit 27e36c0

Please sign in to comment.