fix shape composite

This commit is contained in:
Alexander Wang 2023-06-16 16:50:16 -07:00
parent fffb08a250
commit b30f9702bd
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
3 changed files with 25 additions and 1 deletions

View file

@ -176,7 +176,11 @@ func (c *compiler) compileMap(obj *d2graph.Object, m *d2ir.Map) {
}
shape := m.GetField("shape")
if shape != nil {
c.compileField(obj, shape)
if shape.Composite != nil {
c.errorf(shape.LastPrimaryKey(), "reserved field shape does not accept composite")
} else {
c.compileField(obj, shape)
}
}
for _, f := range m.Fields {
if f.Name == "shape" {

View file

@ -2614,6 +2614,15 @@ object: {
`,
expErr: `d2/testdata/d2compiler/TestCompile/classes-internal-edge.d2:8:3: classes cannot contain an edge`,
},
{
name: "reserved-composite",
text: `shape: sequence_diagram {
alice -> bob: What does it mean\nto be well-adjusted?
bob -> alice: The ability to play bridge or\ngolf as if they were games.
}
`,
expErr: `d2/testdata/d2compiler/TestCompile/reserved-composite.d2:1:1: reserved field shape does not accept composite`,
},
}
for _, tc := range testCases {

View file

@ -0,0 +1,11 @@
{
"graph": null,
"err": {
"errs": [
{
"range": "d2/testdata/d2compiler/TestCompile/reserved-composite.d2,0:0:0-3:1:158",
"errmsg": "d2/testdata/d2compiler/TestCompile/reserved-composite.d2:1:1: reserved field shape does not accept composite"
}
]
}
}