diff --git a/ci/release/changelogs/next.md b/ci/release/changelogs/next.md index 40dfd2879..add6512b6 100644 --- a/ci/release/changelogs/next.md +++ b/ci/release/changelogs/next.md @@ -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) diff --git a/d2compiler/compile.go b/d2compiler/compile.go index 1da1a96ed..2c1fe3916 100644 --- a/d2compiler/compile.go +++ b/d2compiler/compile.go @@ -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 diff --git a/d2compiler/compile_test.go b/d2compiler/compile_test.go index 397770885..ac24f6381 100644 --- a/d2compiler/compile_test.go +++ b/d2compiler/compile_test.go @@ -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 { diff --git a/testdata/d2compiler/TestCompile/no_arrowheads_in_shape.exp.json b/testdata/d2compiler/TestCompile/no_arrowheads_in_shape.exp.json new file mode 100644 index 000000000..0b702370d --- /dev/null +++ b/testdata/d2compiler/TestCompile/no_arrowheads_in_shape.exp.json @@ -0,0 +1,15 @@ +{ + "graph": null, + "err": { + "errs": [ + { + "range": "d2/testdata/d2compiler/TestCompile/no_arrowheads_in_shape.d2,0:2:2-0:18:18", + "errmsg": "d2/testdata/d2compiler/TestCompile/no_arrowheads_in_shape.d2:1:3: \"target-arrowhead\" can only be used on connections" + }, + { + "range": "d2/testdata/d2compiler/TestCompile/no_arrowheads_in_shape.d2,1:2:35-1:18:51", + "errmsg": "d2/testdata/d2compiler/TestCompile/no_arrowheads_in_shape.d2:2:3: \"source-arrowhead\" can only be used on connections" + } + ] + } +}