@@ -1430,9 +1430,9 @@ func (e *ForExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
14301430 })
14311431 return cty .DynamicVal , diags
14321432 }
1433- if ! collVal . IsKnown () {
1434- return cty . DynamicVal , diags
1435- }
1433+
1434+ // Grab the CondExpr marks when we're returning early with an unknown
1435+ var condMarks cty. ValueMarks
14361436
14371437 // Before we start we'll do an early check to see if any CondExpr we've
14381438 // been given is of the wrong type. This isn't 100% reliable (it may
@@ -1460,6 +1460,9 @@ func (e *ForExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
14601460 })
14611461 return cty .DynamicVal , diags
14621462 }
1463+
1464+ _ , condMarks = result .Unmark ()
1465+
14631466 _ , err := convert .Convert (result , cty .Bool )
14641467 if err != nil {
14651468 diags = append (diags , & hcl.Diagnostic {
@@ -1478,6 +1481,10 @@ func (e *ForExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
14781481 }
14791482 }
14801483
1484+ if ! collVal .IsKnown () {
1485+ return cty .DynamicVal .WithMarks (append (marks , condMarks )... ), diags
1486+ }
1487+
14811488 if e .KeyExpr != nil {
14821489 // Producing an object
14831490 var vals map [string ]cty.Value
@@ -1518,6 +1525,12 @@ func (e *ForExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
15181525 known = false
15191526 continue
15201527 }
1528+
1529+ // Extract and merge marks from the include expression into the
1530+ // main set of marks
1531+ _ , includeMarks := includeRaw .Unmark ()
1532+ marks = append (marks , includeMarks )
1533+
15211534 include , err := convert .Convert (includeRaw , cty .Bool )
15221535 if err != nil {
15231536 if known {
@@ -1541,7 +1554,7 @@ func (e *ForExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
15411554
15421555 // Extract and merge marks from the include expression into the
15431556 // main set of marks
1544- includeUnmarked , includeMarks := include .Unmark ()
1557+ includeUnmarked , _ := include .Unmark ()
15451558 marks = append (marks , includeMarks )
15461559 if includeUnmarked .False () {
15471560 // Skip this element
@@ -1566,6 +1579,10 @@ func (e *ForExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
15661579 known = false
15671580 continue
15681581 }
1582+
1583+ _ , keyMarks := keyRaw .Unmark ()
1584+ marks = append (marks , keyMarks )
1585+
15691586 if ! keyRaw .IsKnown () {
15701587 known = false
15711588 continue
@@ -1588,8 +1605,7 @@ func (e *ForExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
15881605 continue
15891606 }
15901607
1591- key , keyMarks := key .Unmark ()
1592- marks = append (marks , keyMarks )
1608+ key , _ = key .Unmark ()
15931609
15941610 val , valDiags := e .ValExpr .Value (childCtx )
15951611 diags = append (diags , valDiags ... )
@@ -1619,7 +1635,7 @@ func (e *ForExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
16191635 }
16201636
16211637 if ! known {
1622- return cty .DynamicVal , diags
1638+ return cty .DynamicVal . WithMarks ( marks ... ) , diags
16231639 }
16241640
16251641 if e .Group {
@@ -1665,6 +1681,12 @@ func (e *ForExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
16651681 known = false
16661682 continue
16671683 }
1684+
1685+ // Extract and merge marks from the include expression into the
1686+ // main set of marks
1687+ _ , includeMarks := includeRaw .Unmark ()
1688+ marks = append (marks , includeMarks )
1689+
16681690 if ! includeRaw .IsKnown () {
16691691 // We will eventually return DynamicVal, but we'll continue
16701692 // iterating in case there are other diagnostics to gather
@@ -1690,10 +1712,7 @@ func (e *ForExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
16901712 continue
16911713 }
16921714
1693- // Extract and merge marks from the include expression into the
1694- // main set of marks
1695- includeUnmarked , includeMarks := include .Unmark ()
1696- marks = append (marks , includeMarks )
1715+ includeUnmarked , _ := include .Unmark ()
16971716 if includeUnmarked .False () {
16981717 // Skip this element
16991718 continue
@@ -1706,7 +1725,7 @@ func (e *ForExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
17061725 }
17071726
17081727 if ! known {
1709- return cty .DynamicVal , diags
1728+ return cty .DynamicVal . WithMarks ( marks ... ) , diags
17101729 }
17111730
17121731 return cty .TupleVal (vals ).WithMarks (marks ... ), diags
0 commit comments