Skip to content

Commit

Permalink
Merge pull request #1686 from gavin-ts/no-arrowheads-in-shape
Browse files Browse the repository at this point in the history
add compiler error when using arrowheads on shape
  • Loading branch information
gavin-ts authored Oct 28, 2023
2 parents 0a7e6c8 + 100df78 commit d09024e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
1 change: 1 addition & 0 deletions ci/release/changelogs/next.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
- Fixes a panic with a spread substitution in a glob map [#1643](https://github.com/terrastruct/d2/pull/1643)
- Fixes use of `null` in `sql_table` constraints (ty @landmaj) [#1660](https://github.com/terrastruct/d2/pull/1660)
- Fixes elk growing shapes with width/height set [#1679](https://github.com/terrastruct/d2/pull/1679)
- Adds a compiler error when accidentally using an arrowhead on a shape [#1686](https://github.com/terrastruct/d2/pull/1686)
4 changes: 4 additions & 0 deletions d2compiler/compile.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,10 @@ func (c *compiler) compileField(obj *d2graph.Object, f *d2ir.Field) {
return
} else if f.Name == "vars" {
return
} else if f.Name == "source-arrowhead" || f.Name == "target-arrowhead" {
c.errorf(f.LastRef().AST(), `%#v can only be used on connections`, f.Name)
return

} else if isReserved {
c.compileReserved(&obj.Attributes, f)
return
Expand Down
9 changes: 9 additions & 0 deletions d2compiler/compile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2813,6 +2813,15 @@ d2/testdata/d2compiler/TestCompile/text_no_label.d2:15:1: block string cannot be
d2/testdata/d2compiler/TestCompile/text_no_label.d2:4:1: shape text must have a non-empty label
d2/testdata/d2compiler/TestCompile/text_no_label.d2:7:1: shape text must have a non-empty label`,
},
{
name: "no_arrowheads_in_shape",

text: `x.target-arrowhead.shape: cf-one
y.source-arrowhead.shape: cf-one
`,
expErr: `d2/testdata/d2compiler/TestCompile/no_arrowheads_in_shape.d2:1:3: "target-arrowhead" can only be used on connections
d2/testdata/d2compiler/TestCompile/no_arrowheads_in_shape.d2:2:3: "source-arrowhead" can only be used on connections`,
},
}

for _, tc := range testCases {
Expand Down
15 changes: 15 additions & 0 deletions testdata/d2compiler/TestCompile/no_arrowheads_in_shape.exp.json

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

0 comments on commit d09024e

Please sign in to comment.