Skip to content

Commit 0dda67c

Browse files
authored
Merge pull request #65 from docker/nil-check-definition
Add nil check before using a ForExpr's CondExpr
2 parents f93b7eb + 94d4ce2 commit 0dda67c

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

internal/bake/hcl/definition.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ func ResolveExpression(ctx context.Context, definitionLinkSupport bool, manager
170170
return ResolveExpression(ctx, definitionLinkSupport, manager, doc, body, documentURI, position, sourceBlock, attributeName, forExpr.CollExpr)
171171
}
172172

173-
if isInsideRange(forExpr.CondExpr.Range(), position) {
173+
if forExpr.CondExpr != nil && isInsideRange(forExpr.CondExpr.Range(), position) {
174174
return ResolveExpression(ctx, definitionLinkSupport, manager, doc, body, documentURI, position, sourceBlock, attributeName, forExpr.CondExpr)
175175
}
176176
}

internal/bake/hcl/definition_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -906,7 +906,15 @@ func TestDefinition(t *testing.T) {
906906
},
907907
},
908908
{
909-
name: "variable inside a for loop",
909+
name: "variable inside a for loop resolving to upper(var)",
910+
content: "variable varList { default = [\"tag\"] }\ntarget default {\n tags = [for var in varList : var]\n}",
911+
line: 2,
912+
character: 16,
913+
locations: nil,
914+
links: nil,
915+
},
916+
{
917+
name: "variable inside a for loop resolving to upper(var)",
910918
content: "variable varList { default = [\"tag\"] }\ntarget default {\n tags = [for var in varList : upper(var)]\n}",
911919
line: 2,
912920
character: 24,

0 commit comments

Comments
 (0)