fix var panic

This commit is contained in:
Alexander Wang 2025-03-14 21:17:41 -06:00
parent f277522b2a
commit cc1e647dfc
No known key found for this signature in database
GPG key ID: BE3937D0D52D8927
2 changed files with 61 additions and 0 deletions

View file

@ -1134,6 +1134,10 @@ func (c *compiler) extendLinks(m *Map, importF *Field, importDir string) {
nodeBoardKind := NodeBoardKind(m)
importIDA := IDA(importF)
for _, f := range m.Fields {
// A substitute or such
if f.Name == nil {
continue
}
if f.Name.ScalarString() == "link" && f.Name.IsUnquoted() {
if nodeBoardKind != "" {
c.errorf(f.LastRef().AST(), "a board itself cannot be linked; only objects within a board can be linked")

View file

@ -0,0 +1,57 @@
{
"graph": {
"name": "",
"isFolderOnly": true,
"ast": {
"range": "d2/testdata/d2compiler/TestCompile/import-var-chain.d2,0:0:0-1:0:8",
"nodes": [
{
"import": {
"range": "d2/testdata/d2compiler/TestCompile/import-var-chain.d2,0:0:0-0:7:7",
"spread": true,
"pre": "",
"path": [
{
"unquoted_string": {
"range": "d2/testdata/d2compiler/TestCompile/import-var-chain.d2,0:4:4-0:7:7",
"value": [
{
"string": "dev",
"raw_string": "dev"
}
]
}
}
]
}
}
]
},
"root": {
"id": "",
"id_val": "",
"attributes": {
"label": {
"value": ""
},
"labelDimensions": {
"width": 0,
"height": 0
},
"style": {},
"near_key": null,
"shape": {
"value": ""
},
"direction": {
"value": ""
},
"constraint": null
},
"zIndex": 0
},
"edges": null,
"objects": null
},
"err": null
}