Name formatOps' held entry firstReach, and checkNameHeld's path spelling path
This commit is contained in:
@@ -382,26 +382,26 @@ type op struct {
|
|||||||
type formatOps struct {
|
type formatOps struct {
|
||||||
ops []op
|
ops []op
|
||||||
grow int
|
grow int
|
||||||
held map[string]heldName
|
held map[string]firstReach
|
||||||
heldLocal bool // some held name is not a reference path, so expand makes a hold
|
heldLocal bool // some held name is not a reference path, so expand makes a hold
|
||||||
}
|
}
|
||||||
|
|
||||||
// heldName is how a format first reaches a held name: the reader holding it, for
|
// firstReach is how a format first reaches a held name: the reader holding it, for
|
||||||
// error messages, and the first path starting from it, "" where none does.
|
// error messages, and the first path starting from it, "" where none does.
|
||||||
type heldName struct {
|
type firstReach struct {
|
||||||
holder string
|
holder string
|
||||||
path string
|
path string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *formatOps) holdName(a arm, label string) {
|
func (c *formatOps) holdName(a arm, label string) {
|
||||||
if c.held == nil {
|
if c.held == nil {
|
||||||
c.held = map[string]heldName{}
|
c.held = map[string]firstReach{}
|
||||||
}
|
}
|
||||||
if !isRef(a.head) || len(a.tail) == 0 {
|
if !isRef(a.head) || len(a.tail) == 0 {
|
||||||
c.heldLocal = true
|
c.heldLocal = true
|
||||||
}
|
}
|
||||||
h, named := c.held[a.head]
|
h, seen := c.held[a.head]
|
||||||
if !named {
|
if !seen {
|
||||||
h.holder = label
|
h.holder = label
|
||||||
}
|
}
|
||||||
if len(a.tail) > 0 && h.path == "" {
|
if len(a.tail) > 0 && h.path == "" {
|
||||||
|
|||||||
+3
-3
@@ -71,14 +71,14 @@ func checkNameHeld(t *template, name string, readers []reader) error {
|
|||||||
if len(held) == 0 {
|
if len(held) == 0 {
|
||||||
return nil // a fixed head holds nothing to reach
|
return nil // a fixed head holds nothing to reach
|
||||||
}
|
}
|
||||||
reader := t.compiled.held[name].path
|
path := t.compiled.held[name].path
|
||||||
seen := map[node]bool{}
|
seen := map[node]bool{}
|
||||||
for _, e := range renderEdges(t) {
|
for _, e := range renderEdges(t) {
|
||||||
if e.read.head == name || !renders(e.to, held, seen) {
|
if e.read.head == name || !renders(e.to, held, seen) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if reader != "" {
|
if path != "" {
|
||||||
return fmt.Errorf("%s renders %q, which {%s} reads a path into; name the fields you want instead", e.reached(), name, reader)
|
return fmt.Errorf("%s renders %q, which {%s} reads a path into; name the fields you want instead", e.reached(), name, path)
|
||||||
}
|
}
|
||||||
return fmt.Errorf("%s renders %q, which a {%s()} also reads; reach it one way so it is drawn once", e.reached(), name, operandReader(t, name))
|
return fmt.Errorf("%s renders %q, which a {%s()} also reads; reach it one way so it is drawn once", e.reached(), name, operandReader(t, name))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user