Commit bf0cbde7 authored by Daniel Martí's avatar Daniel Martí

schema/gen/go: prevent some unkeyed literal vet errors

In particular, use keys for ipld error structs. These have one field, so
the changes are pretty simple.

Reduces 'go vet ./...' from 2647 lines of output to 2365.

Updates #102.
parent d02c3602
......@@ -32,7 +32,7 @@ func (plainList) LookupByNode(ipld.Node) (ipld.Node, error) {
}
func (n *plainList) LookupByIndex(idx int64) (ipld.Node, error) {
if n.Length() <= idx {
return nil, ipld.ErrNotExists{ipld.PathSegmentOfInt(idx)}
return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfInt(idx)}
}
return n.x[idx], nil
}
......
......@@ -36,7 +36,7 @@ func (plainMap) Kind() ipld.Kind {
func (n *plainMap) LookupByString(key string) (ipld.Node, error) {
v, exists := n.m[key]
if !exists {
return nil, ipld.ErrNotExists{ipld.PathSegmentOfString(key)}
return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)}
}
return v, nil
}
......@@ -249,7 +249,7 @@ func (ma *plainMap__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, erro
// Check for dup keys; error if so.
_, exists := ma.w.m[k]
if exists {
return nil, ipld.ErrRepeatedMapKey{plainString(k)}
return nil, ipld.ErrRepeatedMapKey{Key: plainString(k)}
}
ma.state = maState_midValue
ma.w.t = append(ma.w.t, plainMap__Entry{k: plainString(k)})
......@@ -329,7 +329,7 @@ func (mka *plainMap__KeyAssembler) AssignString(v string) error {
if exists {
mka.ma.state = maState_initial
mka.ma = nil // invalidate self to prevent further incorrect use.
return ipld.ErrRepeatedMapKey{plainString(v)}
return ipld.ErrRepeatedMapKey{Key: plainString(v)}
}
// Assign the key into the end of the entry table;
// we'll be doing map insertions after we get the value in hand.
......
......@@ -311,7 +311,7 @@ func (n Map__String__Msg3) LookupByString(k string) (ipld.Node, error) {
}
v, exists := n.m[k2]
if !exists {
return nil, ipld.ErrNotExists{ipld.PathSegmentOfString(k)}
return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(k)}
}
return v, nil
}
......@@ -323,7 +323,7 @@ func (n Map__String__Msg3) LookupByNode(k ipld.Node) (ipld.Node, error) {
}
v, exists := n.m[*k2]
if !exists {
return nil, ipld.ErrNotExists{ipld.PathSegmentOfString(k2.String())}
return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(k2.String())}
}
return v, nil
}
......@@ -572,7 +572,7 @@ func (ma *_Map__String__Msg3__Assembler) AssembleEntry(k string) (ipld.NodeAssem
return nil, err // TODO wrap in some kind of ErrInvalidKey
}
if _, exists := ma.w.m[k2]; exists {
return nil, ipld.ErrRepeatedMapKey{&k2}
return nil, ipld.ErrRepeatedMapKey{Key: &k2}
}
ma.w.t = append(ma.w.t, _Map__String__Msg3__entry{k: k2})
tz := &ma.w.t[len(ma.w.t)-1]
......@@ -914,7 +914,7 @@ func (ma *_Map__String__Msg3__ReprAssembler) AssembleEntry(k string) (ipld.NodeA
return nil, err // TODO wrap in some kind of ErrInvalidKey
}
if _, exists := ma.w.m[k2]; exists {
return nil, ipld.ErrRepeatedMapKey{&k2}
return nil, ipld.ErrRepeatedMapKey{Key: &k2}
}
ma.w.t = append(ma.w.t, _Map__String__Msg3__entry{k: k2})
tz := &ma.w.t[len(ma.w.t)-1]
......@@ -1332,7 +1332,7 @@ func (ma *_Msg3__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, error)
switch k {
case "whee":
if ma.s&fieldBit__Msg3_Whee != 0 {
return nil, ipld.ErrRepeatedMapKey{&fieldName__Msg3_Whee}
return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__Msg3_Whee}
}
ma.s += fieldBit__Msg3_Whee
ma.state = maState_midValue
......@@ -1342,7 +1342,7 @@ func (ma *_Msg3__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, error)
return &ma.ca_whee, nil
case "woot":
if ma.s&fieldBit__Msg3_Woot != 0 {
return nil, ipld.ErrRepeatedMapKey{&fieldName__Msg3_Woot}
return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__Msg3_Woot}
}
ma.s += fieldBit__Msg3_Woot
ma.state = maState_midValue
......@@ -1352,7 +1352,7 @@ func (ma *_Msg3__Assembler) AssembleEntry(k string) (ipld.NodeAssembler, error)
return &ma.ca_woot, nil
case "waga":
if ma.s&fieldBit__Msg3_Waga != 0 {
return nil, ipld.ErrRepeatedMapKey{&fieldName__Msg3_Waga}
return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__Msg3_Waga}
}
ma.s += fieldBit__Msg3_Waga
ma.state = maState_midValue
......@@ -1478,21 +1478,21 @@ func (ka *_Msg3__KeyAssembler) AssignString(k string) error {
switch k {
case "whee":
if ka.s&fieldBit__Msg3_Whee != 0 {
return ipld.ErrRepeatedMapKey{&fieldName__Msg3_Whee}
return ipld.ErrRepeatedMapKey{Key: &fieldName__Msg3_Whee}
}
ka.s += fieldBit__Msg3_Whee
ka.state = maState_expectValue
ka.f = 0
case "woot":
if ka.s&fieldBit__Msg3_Woot != 0 {
return ipld.ErrRepeatedMapKey{&fieldName__Msg3_Woot}
return ipld.ErrRepeatedMapKey{Key: &fieldName__Msg3_Woot}
}
ka.s += fieldBit__Msg3_Woot
ka.state = maState_expectValue
ka.f = 1
case "waga":
if ka.s&fieldBit__Msg3_Waga != 0 {
return ipld.ErrRepeatedMapKey{&fieldName__Msg3_Waga}
return ipld.ErrRepeatedMapKey{Key: &fieldName__Msg3_Waga}
}
ka.s += fieldBit__Msg3_Waga
ka.state = maState_expectValue
......@@ -1813,7 +1813,7 @@ func (ma *_Msg3__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssembler, err
switch k {
case "whee":
if ma.s&fieldBit__Msg3_Whee != 0 {
return nil, ipld.ErrRepeatedMapKey{&fieldName__Msg3_Whee_serial}
return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__Msg3_Whee_serial}
}
ma.s += fieldBit__Msg3_Whee
ma.state = maState_midValue
......@@ -1823,7 +1823,7 @@ func (ma *_Msg3__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssembler, err
return &ma.ca_whee, nil
case "woot":
if ma.s&fieldBit__Msg3_Woot != 0 {
return nil, ipld.ErrRepeatedMapKey{&fieldName__Msg3_Woot_serial}
return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__Msg3_Woot_serial}
}
ma.s += fieldBit__Msg3_Woot
ma.state = maState_midValue
......@@ -1833,7 +1833,7 @@ func (ma *_Msg3__ReprAssembler) AssembleEntry(k string) (ipld.NodeAssembler, err
return &ma.ca_woot, nil
case "waga":
if ma.s&fieldBit__Msg3_Waga != 0 {
return nil, ipld.ErrRepeatedMapKey{&fieldName__Msg3_Waga_serial}
return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__Msg3_Waga_serial}
}
ma.s += fieldBit__Msg3_Waga
ma.state = maState_midValue
......@@ -1960,7 +1960,7 @@ func (ka *_Msg3__ReprKeyAssembler) AssignString(k string) error {
switch k {
case "whee":
if ka.s&fieldBit__Msg3_Whee != 0 {
return ipld.ErrRepeatedMapKey{&fieldName__Msg3_Whee_serial}
return ipld.ErrRepeatedMapKey{Key: &fieldName__Msg3_Whee_serial}
}
ka.s += fieldBit__Msg3_Whee
ka.state = maState_expectValue
......@@ -1968,7 +1968,7 @@ func (ka *_Msg3__ReprKeyAssembler) AssignString(k string) error {
return nil
case "woot":
if ka.s&fieldBit__Msg3_Woot != 0 {
return ipld.ErrRepeatedMapKey{&fieldName__Msg3_Woot_serial}
return ipld.ErrRepeatedMapKey{Key: &fieldName__Msg3_Woot_serial}
}
ka.s += fieldBit__Msg3_Woot
ka.state = maState_expectValue
......@@ -1976,7 +1976,7 @@ func (ka *_Msg3__ReprKeyAssembler) AssignString(k string) error {
return nil
case "waga":
if ka.s&fieldBit__Msg3_Waga != 0 {
return ipld.ErrRepeatedMapKey{&fieldName__Msg3_Waga_serial}
return ipld.ErrRepeatedMapKey{Key: &fieldName__Msg3_Waga_serial}
}
ka.s += fieldBit__Msg3_Waga
ka.state = maState_expectValue
......
This diff is collapsed.
......@@ -142,7 +142,8 @@ type typeSlab struct {
// --- type definitions follow ---
// AnyScalar matches the IPLD Schema type "AnyScalar". It has Union type-kind, and may be interrogated like map kind.
// AnyScalar matches the IPLD Schema type "AnyScalar".
// AnyScalar has Union typekind, which means its data model behaviors are that of a map kind.
type AnyScalar = *_AnyScalar
type _AnyScalar struct {
tag uint
......@@ -170,7 +171,8 @@ type _Bool struct{ x bool }
type Bytes = *_Bytes
type _Bytes struct{ x []byte }
// EnumRepresentation matches the IPLD Schema type "EnumRepresentation". It has Union type-kind, and may be interrogated like map kind.
// EnumRepresentation matches the IPLD Schema type "EnumRepresentation".
// EnumRepresentation has Union typekind, which means its data model behaviors are that of a map kind.
type EnumRepresentation = *_EnumRepresentation
type _EnumRepresentation struct {
tag uint
......@@ -222,7 +224,8 @@ type _Float struct{ x float64 }
type Int = *_Int
type _Int struct{ x int64 }
// ListRepresentation matches the IPLD Schema type "ListRepresentation". It has Union type-kind, and may be interrogated like map kind.
// ListRepresentation matches the IPLD Schema type "ListRepresentation".
// ListRepresentation has Union typekind, which means its data model behaviors are that of a map kind.
type ListRepresentation = *_ListRepresentation
type _ListRepresentation struct {
tag uint
......@@ -251,7 +254,8 @@ type _List__TypeName struct {
x []_TypeName
}
// MapRepresentation matches the IPLD Schema type "MapRepresentation". It has Union type-kind, and may be interrogated like map kind.
// MapRepresentation matches the IPLD Schema type "MapRepresentation".
// MapRepresentation has Union typekind, which means its data model behaviors are that of a map kind.
type MapRepresentation = *_MapRepresentation
type _MapRepresentation struct {
tag uint
......@@ -372,7 +376,8 @@ type _StructField struct {
nullable _Bool
}
// StructRepresentation matches the IPLD Schema type "StructRepresentation". It has Union type-kind, and may be interrogated like map kind.
// StructRepresentation matches the IPLD Schema type "StructRepresentation".
// StructRepresentation has Union typekind, which means its data model behaviors are that of a map kind.
type StructRepresentation = *_StructRepresentation
type _StructRepresentation struct {
tag uint
......@@ -446,7 +451,8 @@ type _TypeCopy struct {
fromType _TypeName
}
// TypeDefn matches the IPLD Schema type "TypeDefn". It has Union type-kind, and may be interrogated like map kind.
// TypeDefn matches the IPLD Schema type "TypeDefn".
// TypeDefn has Union typekind, which means its data model behaviors are that of a map kind.
type TypeDefn = *_TypeDefn
type _TypeDefn struct {
tag uint
......@@ -480,7 +486,8 @@ func (_TypeStruct) _TypeDefn__member() {}
func (_TypeEnum) _TypeDefn__member() {}
func (_TypeCopy) _TypeDefn__member() {}
// TypeDefnInline matches the IPLD Schema type "TypeDefnInline". It has Union type-kind, and may be interrogated like map kind.
// TypeDefnInline matches the IPLD Schema type "TypeDefnInline".
// TypeDefnInline has Union typekind, which means its data model behaviors are that of a map kind.
type TypeDefnInline = *_TypeDefnInline
type _TypeDefnInline struct {
x _TypeDefnInline__iface
......@@ -536,7 +543,8 @@ type _TypeMap struct {
type TypeName = *_TypeName
type _TypeName struct{ x string }
// TypeNameOrInlineDefn matches the IPLD Schema type "TypeNameOrInlineDefn". It has Union type-kind, and may be interrogated like map kind.
// TypeNameOrInlineDefn matches the IPLD Schema type "TypeNameOrInlineDefn".
// TypeNameOrInlineDefn has Union typekind, which means its data model behaviors are that of a map kind.
type TypeNameOrInlineDefn = *_TypeNameOrInlineDefn
type _TypeNameOrInlineDefn struct {
tag uint
......@@ -569,7 +577,8 @@ type _TypeUnion struct {
representation _UnionRepresentation
}
// UnionRepresentation matches the IPLD Schema type "UnionRepresentation". It has Union type-kind, and may be interrogated like map kind.
// UnionRepresentation matches the IPLD Schema type "UnionRepresentation".
// UnionRepresentation has Union typekind, which means its data model behaviors are that of a map kind.
type UnionRepresentation = *_UnionRepresentation
type _UnionRepresentation struct {
tag uint
......
......@@ -146,7 +146,7 @@ func (g listGenerator) EmitNodeMethodLookupByIndex(w io.Writer) {
doTemplate(`
func (n {{ .Type | TypeSymbol }}) LookupByIndex(idx int64) (ipld.Node, error) {
if n.Length() <= idx {
return nil, ipld.ErrNotExists{ipld.PathSegmentOfInt(idx)}
return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfInt(idx)}
}
v := &n.x[idx]
{{- if .Type.ValueIsNullable }}
......
......@@ -178,7 +178,7 @@ func (g mapGenerator) EmitNodeMethodLookupByString(w io.Writer) {
{{- end}}
v, exists := n.m[k2]
if !exists {
return nil, ipld.ErrNotExists{ipld.PathSegmentOfString(k)}
return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(k)}
}
{{- if .Type.ValueIsNullable }}
if v.m == schema.Maybe_Null {
......@@ -206,7 +206,7 @@ func (g mapGenerator) EmitNodeMethodLookupByNode(w io.Writer) {
}
v, exists := n.m[*k2]
if !exists {
return nil, ipld.ErrNotExists{ipld.PathSegmentOfString(k2.String())}
return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(k2.String())}
}
{{- if .Type.ValueIsNullable }}
if v.m == schema.Maybe_Null {
......
......@@ -428,7 +428,7 @@ func (g structBuilderGenerator) emitMapAssemblerMethods(w io.Writer) {
{{- range $i, $field := .Type.Fields }}
case "{{ $field.Name }}":
if ma.s & fieldBit__{{ $type | TypeSymbol }}_{{ $field | FieldSymbolUpper }} != 0 {
return nil, ipld.ErrRepeatedMapKey{&fieldName__{{ $type | TypeSymbol }}_{{ $field | FieldSymbolUpper }}}
return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__{{ $type | TypeSymbol }}_{{ $field | FieldSymbolUpper }}}
}
ma.s += fieldBit__{{ $type | TypeSymbol }}_{{ $field | FieldSymbolUpper }}
ma.state = maState_midValue
......@@ -565,7 +565,7 @@ func (g structBuilderGenerator) emitKeyAssembler(w io.Writer) {
{{- range $i, $field := .Type.Fields }}
case "{{ $field.Name }}":
if ka.s & fieldBit__{{ $type | TypeSymbol }}_{{ $field | FieldSymbolUpper }} != 0 {
return ipld.ErrRepeatedMapKey{&fieldName__{{ $type | TypeSymbol }}_{{ $field | FieldSymbolUpper }}}
return ipld.ErrRepeatedMapKey{Key: &fieldName__{{ $type | TypeSymbol }}_{{ $field | FieldSymbolUpper }}}
}
ka.s += fieldBit__{{ $type | TypeSymbol }}_{{ $field | FieldSymbolUpper }}
ka.state = maState_expectValue
......
......@@ -87,7 +87,7 @@ func (g structReprMapReprGenerator) EmitNodeMethodLookupByString(w io.Writer) {
case "{{ $field | $field.Parent.RepresentationStrategy.GetFieldKey }}":
{{- if $field.IsOptional }}
if n.{{ $field | FieldSymbolLower }}.m == schema.Maybe_Absent {
return ipld.Absent, ipld.ErrNotExists{ipld.PathSegmentOfString(key)}
return ipld.Absent, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)}
}
{{- end}}
{{- if $field.IsNullable }}
......@@ -466,7 +466,7 @@ func (g structReprMapReprBuilderGenerator) emitMapAssemblerMethods(w io.Writer)
{{- range $i, $field := .Type.Fields }}
case "{{ $field | $type.RepresentationStrategy.GetFieldKey }}":
if ma.s & fieldBit__{{ $type | TypeSymbol }}_{{ $field | FieldSymbolUpper }} != 0 {
return nil, ipld.ErrRepeatedMapKey{&fieldName__{{ $type | TypeSymbol }}_{{ $field | FieldSymbolUpper }}_serial}
return nil, ipld.ErrRepeatedMapKey{Key: &fieldName__{{ $type | TypeSymbol }}_{{ $field | FieldSymbolUpper }}_serial}
}
ma.s += fieldBit__{{ $type | TypeSymbol }}_{{ $field | FieldSymbolUpper }}
ma.state = maState_midValue
......@@ -605,7 +605,7 @@ func (g structReprMapReprBuilderGenerator) emitKeyAssembler(w io.Writer) {
{{- range $i, $field := .Type.Fields }}
case "{{ $field | $type.RepresentationStrategy.GetFieldKey }}":
if ka.s & fieldBit__{{ $type | TypeSymbol }}_{{ $field | FieldSymbolUpper }} != 0 {
return ipld.ErrRepeatedMapKey{&fieldName__{{ $type | TypeSymbol }}_{{ $field | FieldSymbolUpper }}_serial}
return ipld.ErrRepeatedMapKey{Key: &fieldName__{{ $type | TypeSymbol }}_{{ $field | FieldSymbolUpper }}_serial}
}
ka.s += fieldBit__{{ $type | TypeSymbol }}_{{ $field | FieldSymbolUpper }}
ka.state = maState_expectValue
......
......@@ -84,7 +84,7 @@ func (g structReprTupleReprGenerator) EmitNodeMethodLookupByIndex(w io.Writer) {
case {{ $i }}:
{{- if $field.IsOptional }}
if n.{{ $field | FieldSymbolLower }}.m == schema.Maybe_Absent {
return ipld.Absent, ipld.ErrNotExists{ipld.PathSegmentOfInt(idx)}
return ipld.Absent, ipld.ErrNotExists{Segment: ipld.PathSegmentOfInt(idx)}
}
{{- end}}
{{- if $field.IsNullable }}
......
......@@ -157,14 +157,14 @@ func (g unionGenerator) EmitNodeMethodLookupByString(w io.Writer) {
case "{{ $member.Name }}":
{{- if (eq (dot.AdjCfg.UnionMemlayout dot.Type) "embedAll") }}
if n.tag != {{ add $i 1 }} {
return nil, ipld.ErrNotExists{ipld.PathSegmentOfString(key)}
return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)}
}
return &n.x{{ add $i 1 }}, nil
{{- else if (eq (dot.AdjCfg.UnionMemlayout dot.Type) "interface") }}
if n2, ok := n.x.({{ $member | TypeSymbol }}); ok {
return n2, nil
} else {
return nil, ipld.ErrNotExists{ipld.PathSegmentOfString(key)}
return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)}
}
{{- end}}
{{- end}}
......
......@@ -86,14 +86,14 @@ func (g unionReprKeyedReprGenerator) EmitNodeMethodLookupByString(w io.Writer) {
case "{{ $member | dot.Type.RepresentationStrategy.GetDiscriminant }}":
{{- if (eq (dot.AdjCfg.UnionMemlayout dot.Type) "embedAll") }}
if n.tag != {{ add $i 1 }} {
return nil, ipld.ErrNotExists{ipld.PathSegmentOfString(key)}
return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)}
}
return n.x{{ add $i 1 }}.Representation(), nil
{{- else if (eq (dot.AdjCfg.UnionMemlayout dot.Type) "interface") }}
if n2, ok := n.x.({{ $member | TypeSymbol }}); ok {
return n2.Representation(), nil
} else {
return nil, ipld.ErrNotExists{ipld.PathSegmentOfString(key)}
return nil, ipld.ErrNotExists{Segment: ipld.PathSegmentOfString(key)}
}
{{- end}}
{{- end}}
......
......@@ -227,7 +227,7 @@ func emitNodeAssemblerHelper_mapoid_mapAssemblerMethods(w io.Writer, adjCfg *Adj
}
{{- end}}
if _, exists := ma.w.m[k2]; exists {
return nil, ipld.ErrRepeatedMapKey{&k2}
return nil, ipld.ErrRepeatedMapKey{Key: &k2}
}
ma.w.t = append(ma.w.t, _{{ .Type | TypeSymbol }}__entry{k: k2})
tz := &ma.w.t[len(ma.w.t)-1]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment