Skip to content

Commit

Permalink
Merge pull request #1415 from alixander/no-composite
Browse files Browse the repository at this point in the history
fix `shape` accepting composite
  • Loading branch information
alixander authored Jun 16, 2023
2 parents fffb08a + cdf5681 commit 3253ba6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

- Display version on CLI help invocation [#1400](https://github.com/terrastruct/d2/pull/1400)
- Improved readability of connection labels when they overlap another connection. [#447](https://github.com/terrastruct/d2/pull/447)
- Error message when `shape` is given a composite [#1415](https://github.com/terrastruct/d2/pull/1415)

#### Bugfixes ⛑️

Expand Down
6 changes: 5 additions & 1 deletion d2compiler/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down
9 changes: 9 additions & 0 deletions d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
11 changes: 11 additions & 0 deletions testdata/d2compiler/TestCompile/reserved-composite.exp.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3253ba6

Please sign in to comment.