Name the typed spelling for a column read whose values hold the datatype beside it, and say holding for a datatype taken from a column read
Tests / vet + fmt + tests (pull_request) Successful in 1m2s
Tests / vet + fmt + tests (push) Successful in 7s

This commit was merged in pull request #15.
This commit is contained in:
2026-09-15 21:44:36 +02:00
parent 1e60d52e48
commit 72a6ef9071
+18 -6
View File
@@ -171,22 +171,34 @@ func disagreement(a *template, da DataType, b *template, db DataType) error {
case bare.fromString: // an object may carry a weight, which this spelling would drop case bare.fromString: // an object may carry a weight, which this spelling would drop
return fmt.Errorf(`item %q declares no datatype, and a column holds one; write it as {"format":%q,"datatype":%q}`, bare.format, bare.format, want) return fmt.Errorf(`item %q declares no datatype, and a column holds one; write it as {"format":%q,"datatype":%q}`, bare.format, bare.format, want)
} }
return fmt.Errorf(`item %q declares no datatype beside one declaring %s; a column holds one, so give it "datatype": %q`, bare.format, want, want) return fmt.Errorf(`item %q declares no datatype beside one holding %s; a column holds one, so give it "datatype": %q`, bare.format, want, want)
} }
// bothTyped names the fix for two items holding different datatypes: reading one that takes its // bothTyped names the fix for two items holding different datatypes: the one taking its datatype
// datatype from the column it reads as text, since only a declared datatype can be edited away. // from the column it reads is typed as the other where its values prove it, else read as text.
func bothTyped(a *template, da DataType, b *template, db DataType) error { func bothTyped(a *template, da DataType, b *template, db DataType) error {
read := a read, other := a, db
if a.datatype != DataTypeString { if a.datatype != DataTypeString {
read = b read, other = b, da
} }
if read.datatype != DataTypeString { switch {
case read.datatype != DataTypeString:
return fmt.Errorf("its items hold %s and %s; a column holds one datatype", da, db) return fmt.Errorf("its items hold %s and %s; a column holds one datatype", da, db)
case (&valueProof{}).columnItem(read).not[other] == "":
return fmt.Errorf("its items hold %s and %s; a column holds one datatype, so %s", da, db, typedAs(read, other))
} }
return fmt.Errorf("its items hold %s and %s; a column holds one datatype, so to read %q as text, %s", da, db, read.format, asText(read)) return fmt.Errorf("its items hold %s and %s; a column holds one datatype, so to read %q as text, %s", da, db, read.format, asText(read))
} }
// typedAs names the spelling giving a column-read item datatype d, keeping the other keys an object
// item carries.
func typedAs(t *template, d DataType) string {
if t.fromString {
return fmt.Sprintf(`write %q as {"format":%q,"datatype":%q}`, t.format, t.format, d)
}
return fmt.Sprintf(`give %q "datatype": %q`, t.format, d)
}
// asText names the spelling that reads the column a column-read item reads as text, keeping the // asText names the spelling that reads the column a column-read item reads as text, keeping the
// other keys an object item carries. // other keys an object item carries.
func asText(t *template) string { func asText(t *template) string {