Pick a column disagreement's wording from one swap, one proof and one switch

This commit is contained in:
2026-09-28 10:55:49 +02:00
committed by Lillem4n
parent 2254b33f0e
commit 6afe16ba01
2 changed files with 16 additions and 28 deletions
+16 -26
View File
@@ -157,37 +157,27 @@ func columnItems(n node) (items []*template, nullable bool) {
return items, nullable
}
// disagreement names the fix for two items of one column holding different datatypes.
// disagreement names the fix for two items of one column holding different datatypes. The item to
// fix declares none, and is text where the other reads a typed column.
func disagreement(a *template, da DataType, b *template, db DataType) error {
bare, typed, want := b, a, da
if da == DataTypeString {
bare, typed, want = a, b, db
fix, has, other, want := a, da, b, db
if da != DataTypeString && (a.datatype != DataTypeString || db == DataTypeString) {
fix, has, other, want = b, db, a, da
}
proven := (&valueProof{}).proveColumnItem(fix).not[want] == ""
switch {
case da != DataTypeString && db != DataTypeString:
return bothTyped(a, da, b, db)
case typed.datatype == DataTypeString && (&valueProof{}).proveColumnItem(bare).not[want] != "":
return fmt.Errorf(`item %q is not %s, the datatype item %q takes from the column it reads; to read that column as text, %s`, bare.format, dataTypeNouns[want], typed.format, asText(typed))
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 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: the one taking its datatype
// 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 {
read, other := a, db
if a.datatype != DataTypeString {
read, other = b, da
}
switch {
case read.datatype != DataTypeString:
case fix.datatype != DataTypeString:
return fmt.Errorf("its items hold %s and %s; a column holds one datatype", da, db)
case (&valueProof{}).proveColumnItem(read).not[other] == "":
return fmt.Errorf("its items hold %s and %s; a column holds one datatype, so %s", da, db, typedAs(read, other))
case has != DataTypeString && proven:
return fmt.Errorf("its items hold %s and %s; a column holds one datatype, so %s", da, db, typedAs(fix, want))
case has != DataTypeString:
return fmt.Errorf("its items hold %s and %s; a column holds one datatype, so to read %q as text, %s", da, db, fix.format, asText(fix))
case other.datatype == DataTypeString && !proven:
return fmt.Errorf(`item %q is not %s, the datatype item %q takes from the column it reads; to read that column as text, %s`, fix.format, dataTypeNouns[want], other.format, asText(other))
case fix.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}`, fix.format, fix.format, want)
}
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(`item %q declares no datatype beside one holding %s; a column holds one, so give it "datatype": %q`, fix.format, want, want)
}
// typedAs names the spelling giving a column-read item datatype d, keeping the other keys an object