Struct-filling: FakeStruct fills fake-tagged fields as a record, each field's Go type its datatype, and IsTemplate owns the path-or-template shape rule
Tests / vet + fmt + tests (pull_request) Successful in 1m0s

This commit is contained in:
2026-09-15 16:23:10 +02:00
parent d4ff3b242e
commit c0b176a839
8 changed files with 424 additions and 46 deletions
+20 -13
View File
@@ -67,19 +67,7 @@ func datatypeOf(m map[string]any, pos position) (DataType, error) {
// columnDatatype is the datatype a column's items declare. They must agree, since a
// column holds one; a column only ever null is a string.
func columnDatatype(n node) (DataType, error) {
var items []*template
var collect func(node)
collect = func(n node) {
switch n := n.(type) {
case *choice:
for _, it := range n.items {
collect(it)
}
case *template:
items = append(items, n)
}
}
collect(n)
items, _ := columnItems(n)
if len(items) == 0 {
return DataTypeString, nil
}
@@ -91,6 +79,25 @@ func columnDatatype(n node) (DataType, error) {
return items[0].datatype, nil
}
// columnItems is a column's template items, its choices unwrapped, and whether one is null.
func columnItems(n node) (items []*template, nullable bool) {
var collect func(node)
collect = func(n node) {
switch n := n.(type) {
case *choice:
for _, it := range n.items {
collect(it)
}
case *template:
items = append(items, n)
case *null:
nullable = true
}
}
collect(n)
return items, nullable
}
// disagreement names the fix for two items of one column declaring different datatypes.
func disagreement(a, b *template) error {
typed, bare := a, b