cleanup
This commit is contained in:
parent
78e9e4565e
commit
a6125c46ec
2 changed files with 18 additions and 5 deletions
|
|
@ -3473,6 +3473,19 @@ hi: ${z}
|
|||
`, `d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable "z"`)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "nested-missing",
|
||||
run: func(t *testing.T) {
|
||||
assertCompile(t, `
|
||||
vars: {
|
||||
x: {
|
||||
y: hey
|
||||
}
|
||||
}
|
||||
hi: ${x.z}
|
||||
`, `d2/testdata/d2compiler/TestCompile2/vars/errors/nested-missing.d2:7:1: could not resolve variable "x.z"`)
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "edge",
|
||||
run: func(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -98,11 +98,12 @@ func (c *compiler) overlayClasses(m *Map) {
|
|||
}
|
||||
|
||||
func (c *compiler) resolveSubstitutions(refctx *RefContext) {
|
||||
varsMap := &Map{}
|
||||
boardScope := refctx.ScopeMap
|
||||
if NodeBoardKind(refctx.ScopeMap) == "" {
|
||||
boardScope = ParentBoard(refctx.ScopeMap).Map()
|
||||
}
|
||||
|
||||
varsMap := &Map{}
|
||||
vars := boardScope.GetField("vars")
|
||||
if vars != nil {
|
||||
varsMap = vars.Map()
|
||||
|
|
@ -154,13 +155,12 @@ func (c *compiler) resolveSubstitution(vars *Map, mk *d2ast.Key, substitution *d
|
|||
vars = r.Map()
|
||||
resolved = r
|
||||
}
|
||||
|
||||
if resolved == nil {
|
||||
c.errorf(mk, `could not resolve variable "%s"`, strings.Join(substitution.IDA(), "."))
|
||||
} else if resolved.Composite != nil {
|
||||
c.errorf(mk, `cannot reference map variable "%s"`, strings.Join(substitution.IDA(), "."))
|
||||
} else {
|
||||
if resolved.Composite != nil {
|
||||
c.errorf(mk, `cannot reference map variable "%s"`, strings.Join(substitution.IDA(), "."))
|
||||
return nil
|
||||
}
|
||||
return resolved
|
||||
}
|
||||
return nil
|
||||
|
|
|
|||
Loading…
Reference in a new issue