diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 0236a9ce2..aea9cbfa2 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -705,6 +705,12 @@ func (c *compiler) validateKey(obj *d2graph.Object, f *d2ir.Field) { if !in && arrowheadIn { c.errorf(f.LastPrimaryKey(), fmt.Sprintf(`invalid shape, can only set "%s" for arrowheads`, obj.Attributes.Shape.Value)) } + case "rows", "columns": + for _, child := range obj.ChildrenArray { + if child.IsContainer() { + c.errorf(f.LastPrimaryKey(), fmt.Sprintf(`invalid grid %#v. can only set %#v with no descendants (see %#v)`, obj.AbsID(), keyword, child.ChildrenArray[0].AbsID())) + } + } } return } diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 4afc52fbf..570163653 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -2303,6 +2303,21 @@ obj { d2/testdata/d2compiler/TestCompile/grid_edge.d2:5:2: edge "c -> hey.b" cannot enter grid "hey" d2/testdata/d2compiler/TestCompile/grid_edge.d2:6:2: edge "hey.a -> c" cannot enter grid "hey"`, }, + { + name: "grid_nested", + text: `hey: { + rows: 200 + columns: 200 + + a + b + c + d.invalid descendant +} +`, + expErr: `d2/testdata/d2compiler/TestCompile/grid_nested.d2:2:2: invalid grid "hey". can only set "rows" with no descendants (see "hey.d.invalid descendant") +d2/testdata/d2compiler/TestCompile/grid_nested.d2:3:2: invalid grid "hey". can only set "columns" with no descendants (see "hey.d.invalid descendant")`, + }, } for _, tc := range testCases { diff --git a/testdata/d2compiler/TestCompile/grid_nested.exp.json b/testdata/d2compiler/TestCompile/grid_nested.exp.json new file mode 100644 index 000000000..22f85db05 --- /dev/null +++ b/testdata/d2compiler/TestCompile/grid_nested.exp.json @@ -0,0 +1,16 @@ +{ + "graph": null, + "err": { + "ioerr": null, + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile/grid_nested.d2,1:1:8-1:10:17", + "errmsg": "d2/testdata/d2compiler/TestCompile/grid_nested.d2:2:2: invalid grid \"hey\". can only set \"rows\" with no descendants (see \"hey.d.invalid descendant\")" + }, + { + "range": "d2/testdata/d2compiler/TestCompile/grid_nested.d2,2:1:19-2:13:31", + "errmsg": "d2/testdata/d2compiler/TestCompile/grid_nested.d2:3:2: invalid grid \"hey\". can only set \"columns\" with no descendants (see \"hey.d.invalid descendant\")" + } + ] + } +}