d2ir: fix error handling for composite glob filter

This commit is contained in:
Alexander Wang 2025-04-12 02:14:33 -07:00
parent 75633193a9
commit c366dd8a42
No known key found for this signature in database
GPG key ID: D89FA31966BDBECE
3 changed files with 28 additions and 1 deletions

View file

@ -1714,6 +1714,18 @@ steps: {
assert.Equal(t, 1, len(g.Layers[0].Steps)) assert.Equal(t, 1, len(g.Layers[0].Steps))
}, },
}, },
{
name: "composite-glob-filter",
text: `
*: {
&shape: [a; b]
}
k
`,
expErr: `d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2:3:3: glob filters cannot be composites
d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2:3:3: glob filters cannot be composites`,
},
{ {
name: "import-nested-var", name: "import-nested-var",

View file

@ -796,7 +796,7 @@ func (c *compiler) ampersandFilter(refctx *RefContext) bool {
return false return false
} }
if len(fa) == 0 { if len(fa) == 0 {
if refctx.Key.Value.ScalarBox().Unbox().ScalarString() == "*" { if refctx.Key.Value.ScalarBox().Unbox() != nil && refctx.Key.Value.ScalarBox().Unbox().ScalarString() == "*" {
return false return false
} }
// The field/edge has no value for this filter // The field/edge has no value for this filter

View file

@ -0,0 +1,15 @@
{
"graph": null,
"err": {
"errs": [
{
"range": "d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2,2:2:8-2:16:22",
"errmsg": "d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2:3:3: glob filters cannot be composites"
},
{
"range": "d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2,2:2:8-2:16:22",
"errmsg": "d2/testdata/d2compiler/TestCompile/composite-glob-filter.d2:3:3: glob filters cannot be composites"
}
]
}
}