Replace disagreements' ten keys with the rule they encode

This commit is contained in:
2026-09-29 09:58:01 +02:00
committed by Lillem4n
parent c15067b942
commit e8469f1f89
2 changed files with 16 additions and 29 deletions
+16 -25
View File
@@ -174,25 +174,6 @@ type itemPair struct {
want DataType want DataType
} }
// disagreementKey is the two items' kinds and whether fix's values prove to hold want.
type disagreementKey struct {
fix, other itemKind
proven bool
}
var disagreements = map[disagreementKey]func(d itemPair) error{
{kindDeclares, kindDeclares, false}: holdOne,
{kindDeclares, kindDeclares, true}: holdOne,
{kindReads, kindDeclares, false}: readAsText,
{kindReads, kindDeclares, true}: readTyped,
{kindReads, kindReads, false}: readAsText,
{kindReads, kindReads, true}: readTyped,
{kindText, kindDeclares, false}: declare,
{kindText, kindDeclares, true}: declare,
{kindText, kindReads, false}: otherAsText,
{kindText, kindReads, true}: declare,
}
// disagreement names the fix for items a and b of one column holding different datatypes, fixing // disagreement names the fix for items a and b of one column holding different datatypes, fixing
// the one that declares least, a when both declare alike. // the one that declares least, a when both declare alike.
func disagreement(a *template, da DataType, b *template, db DataType) error { func disagreement(a *template, da DataType, b *template, db DataType) error {
@@ -201,15 +182,25 @@ func disagreement(a *template, da DataType, b *template, db DataType) error {
d.fix, d.other, d.want = b, a, da d.fix, d.other, d.want = b, a, da
} }
proven := (&valueProof{}).proveColumnItem(d.fix).not[d.want] == "" proven := (&valueProof{}).proveColumnItem(d.fix).not[d.want] == ""
return disagreementFix(disagreementKey{kindOf(d.fix), kindOf(d.other), proven})(d) return disagreementFix(kindOf(d.fix), kindOf(d.other), proven)(d)
} }
func disagreementFix(k disagreementKey) func(d itemPair) error { // disagreementFix is the fix for item fix beside item other, where proven says fix's values hold
fix := disagreements[k] // the other's datatype.
if fix == nil { func disagreementFix(fix, other itemKind, proven bool) func(d itemPair) error {
panic(internalError("no disagreement names the fix for %+v", k)) switch {
case fix == kindDeclares:
return holdOne
case fix == kindReads && proven:
return readTyped
case fix == kindReads:
return readAsText
case other == kindText:
panic(internalError("two text items hold one datatype, so they never disagree"))
case other == kindReads && !proven:
return otherAsText
} }
return fix return declare
} }
func holdOne(d itemPair) error { func holdOne(d itemPair) error {
-4
View File
@@ -28,10 +28,6 @@ ranking `readSurvey.walk` hardest and all seven the unit they would least modify
This round, in order: This round, in order:
- Replace `disagreements`' ten keys with the rule they encode: a declared fix holds one
datatype, a read one is `readTyped` where proven and `readAsText` otherwise, a text one
is `otherAsText` beside an unproven read and `declare` otherwise. Six seats could not
see why each key gets its fix.
- Drop `table.fields` for `formatTemplate.fields`: one map held in two fields. - Drop `table.fields` for `formatTemplate.fields`: one map held in two fields.
- Rename `arm.key` to `head`, as `template.head` reads it, leaving `key` the table's key - Rename `arm.key` to `head`, as `template.head` reads it, leaving `key` the table's key
column; give `renderScope.row` a type that is not `tablePin`, since it pins nothing; column; give `renderScope.row` a type that is not `tablePin`, since it pins nothing;