fix no-primary-composite
This commit is contained in:
parent
4847714c3c
commit
29af92310b
6 changed files with 13 additions and 22 deletions
|
|
@ -281,12 +281,6 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) {
|
||||||
if f.Map() != nil {
|
if f.Map() != nil {
|
||||||
if len(f.Map().Edges) > 0 {
|
if len(f.Map().Edges) > 0 {
|
||||||
c.errorf(f.Map().Edges[0].LastRef().AST(), "vars cannot contain an edge")
|
c.errorf(f.Map().Edges[0].LastRef().AST(), "vars cannot contain an edge")
|
||||||
} else {
|
|
||||||
for _, f := range f.Map().Fields {
|
|
||||||
if f.Primary() == nil && f.Composite == nil {
|
|
||||||
c.errorf(f.LastRef().AST(), "invalid var with no value")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -3797,17 +3797,6 @@ hi: ${z}
|
||||||
`, `d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable "z"`)
|
`, `d2/testdata/d2compiler/TestCompile2/vars/errors/missing.d2:5:1: could not resolve variable "z"`)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "bad-var",
|
|
||||||
run: func(t *testing.T) {
|
|
||||||
assertCompile(t, `
|
|
||||||
vars: {
|
|
||||||
x
|
|
||||||
}
|
|
||||||
hi: ${x}
|
|
||||||
`, `d2/testdata/d2compiler/TestCompile2/vars/errors/bad-var.d2:3:3: invalid var with no value`)
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
name: "multi-part-map",
|
name: "multi-part-map",
|
||||||
run: func(t *testing.T) {
|
run: func(t *testing.T) {
|
||||||
|
|
@ -3818,7 +3807,7 @@ vars: {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hi: 1 ${x}
|
hi: 1 ${x}
|
||||||
`, `d2/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.d2:7:1: cannot substitute map variable "x" as part of a string`)
|
`, `d2/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.d2:7:1: cannot substitute composite variable "x" as part of a string`)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|
@ -3938,7 +3927,7 @@ z: {
|
||||||
d: ...${x}
|
d: ...${x}
|
||||||
c
|
c
|
||||||
}
|
}
|
||||||
`, `d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.d2:8:2: cannot substitute map variable "x" as part of a string`)
|
`, `d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.d2:8:2: cannot substitute composite variable "x" as part of a string`)
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -188,8 +188,12 @@ func (c *compiler) resolveSubstitutions(varsStack []*Map, node Node) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if resolvedField.Primary() == nil {
|
if resolvedField.Primary() == nil {
|
||||||
|
if resolvedField.Composite == nil {
|
||||||
|
c.errorf(node.LastRef().AST(), `cannot substitute variable without value: "%s"`, strings.Join(box.Substitution.IDA(), "."))
|
||||||
|
return
|
||||||
|
}
|
||||||
if len(s.Value) > 1 {
|
if len(s.Value) > 1 {
|
||||||
c.errorf(node.LastRef().AST(), `cannot substitute map variable "%s" as part of a string`, strings.Join(box.Substitution.IDA(), "."))
|
c.errorf(node.LastRef().AST(), `cannot substitute composite variable "%s" as part of a string`, strings.Join(box.Substitution.IDA(), "."))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch n := node.(type) {
|
switch n := node.(type) {
|
||||||
|
|
|
||||||
4
testdata/d2compiler/TestCompile2/vars/errors/bad-var.exp.json
generated
vendored
4
testdata/d2compiler/TestCompile2/vars/errors/bad-var.exp.json
generated
vendored
|
|
@ -5,6 +5,10 @@
|
||||||
{
|
{
|
||||||
"range": "d2/testdata/d2compiler/TestCompile2/vars/errors/bad-var.d2,2:2:11-2:3:12",
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/errors/bad-var.d2,2:2:11-2:3:12",
|
||||||
"errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/bad-var.d2:3:3: invalid var with no value"
|
"errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/bad-var.d2:3:3: invalid var with no value"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/errors/bad-var.d2,4:4:23-4:5:24",
|
||||||
|
"errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/bad-var.d2:5:5: invalid var with no value"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.exp.json
generated
vendored
2
testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.exp.json
generated
vendored
|
|
@ -4,7 +4,7 @@
|
||||||
"errs": [
|
"errs": [
|
||||||
{
|
{
|
||||||
"range": "d2/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.d2,6:0:31-6:2:33",
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.d2,6:0:31-6:2:33",
|
||||||
"errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.d2:7:1: cannot substitute map variable \"x\" as part of a string"
|
"errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/multi-part-map.d2:7:1: cannot substitute composite variable \"x\" as part of a string"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.exp.json
generated
vendored
2
testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.exp.json
generated
vendored
|
|
@ -4,7 +4,7 @@
|
||||||
"errs": [
|
"errs": [
|
||||||
{
|
{
|
||||||
"range": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.d2,7:1:36-7:2:37",
|
"range": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.d2,7:1:36-7:2:37",
|
||||||
"errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.d2:8:2: cannot substitute map variable \"x\" as part of a string"
|
"errmsg": "d2/testdata/d2compiler/TestCompile2/vars/errors/spread-non-solo.d2:8:2: cannot substitute composite variable \"x\" as part of a string"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue