Answer architecture round 2: linkTemplates' doc says which steps pass names as arguments, checkEveryNameRead, and an invariant guard on a binding with no read at link

This commit is contained in:
2026-10-05 22:34:39 +02:00
committed by Lillem4n
parent 0993d86f22
commit 69703dec91
3 changed files with 9 additions and 5 deletions
+2 -2
View File
@@ -62,8 +62,8 @@ type linkedNames struct {
}
// linkTemplates links ts in steps, each over every template before the next starts, each
// returning what it builds and taking what an earlier step built as an argument: the references,
// the names' targets, the compiled formats, the keys and reads of each name, and the column each
// returning what it builds: the references and the compiled formats, kept on each template, the
// names' targets, keys and reads, passed to the steps after as arguments, and the column each
// format reads. The bindings take their targets and keys once every check has passed.
func linkTemplates(ts []linkSite, root map[string]node) error {
for _, s := range ts {
+3 -3
View File
@@ -96,11 +96,11 @@ func bindNames(root node) error {
if err != nil {
return err
}
return checkRead(scopes, read)
return checkEveryNameRead(scopes, read)
}
// checkRead refuses a binding of scopes that read does not hold.
func checkRead(scopes []*nameScope, read map[*nameBinding]bool) error {
// checkEveryNameRead refuses a binding of scopes that nothing reads.
func checkEveryNameRead(scopes []*nameScope, read map[*nameBinding]bool) error {
for _, sc := range scopes {
for _, b := range sc.order {
if !read[b] {
+4
View File
@@ -6,6 +6,7 @@ import (
"strings"
"github.com/larvit/fejkdata/internal/grammar"
"github.com/larvit/fejkdata/internal/invariant"
)
// checkNameReads refuses each binding of t that checkUses refuses, a read of a name inside the
@@ -67,6 +68,9 @@ func rendersInside(nodes []node, t *template) bool {
// template reaches the binder through fields. Where the spelling would be a CLI argument or tag
// of one reference alone, that entry point's own refusal then names the bare path.
func (b *nameBinding) checkUses(uses []nameUse) error {
if len(uses) == 0 {
panic(invariant.Broken("name %q has no read at link, though its compile found one", b.name))
}
r := uses[0]
if len(uses) > 1 || r.nested {
return nil