@@ -12,6 +12,7 @@ import (
12
12
"github.com/google/go-cmp/cmp"
13
13
"github.com/zclconf/go-cty-debug/ctydebug"
14
14
"github.com/zclconf/go-cty/cty"
15
+ "github.com/zclconf/go-cty/cty/function"
15
16
16
17
"github.com/hashicorp/hcl/v2"
17
18
"github.com/hashicorp/hcl/v2/hclsyntax"
@@ -218,6 +219,7 @@ func TestRefineValueSpec(t *testing.T) {
218
219
foo = "hello"
219
220
bar = unk
220
221
dyn = dyn
222
+ marked = mark(unk)
221
223
`
222
224
223
225
f , diags := hclsyntax .ParseConfig ([]byte (config ), "" , hcl .InitialPos )
@@ -256,16 +258,37 @@ dyn = dyn
256
258
}
257
259
}
258
260
spec := & ObjectSpec {
259
- "foo" : attrSpec ("foo" ),
260
- "bar" : attrSpec ("bar" ),
261
- "dyn" : attrSpec ("dyn" ),
261
+ "foo" : attrSpec ("foo" ),
262
+ "bar" : attrSpec ("bar" ),
263
+ "dyn" : attrSpec ("dyn" ),
264
+ "marked" : attrSpec ("marked" ),
262
265
}
263
266
264
267
got , diags := Decode (f .Body , spec , & hcl.EvalContext {
265
268
Variables : map [string ]cty.Value {
266
269
"unk" : cty .UnknownVal (cty .String ),
267
270
"dyn" : cty .DynamicVal ,
268
271
},
272
+ Functions : map [string ]function.Function {
273
+ "mark" : function .New (& function.Spec {
274
+ Params : []function.Parameter {
275
+ {
276
+ Name : "v" ,
277
+ Type : cty .DynamicPseudoType ,
278
+ AllowMarked : true ,
279
+ AllowNull : true ,
280
+ AllowUnknown : true ,
281
+ AllowDynamicType : true ,
282
+ },
283
+ },
284
+ Type : func (args []cty.Value ) (cty.Type , error ) {
285
+ return args [0 ].Type (), nil
286
+ },
287
+ Impl : func (args []cty.Value , retType cty.Type ) (cty.Value , error ) {
288
+ return args [0 ].Mark ("boop" ), nil
289
+ },
290
+ }),
291
+ },
269
292
})
270
293
if diags .HasErrors () {
271
294
t .Fatal (diags .Error ())
@@ -284,6 +307,10 @@ dyn = dyn
284
307
// Correct behavior here requires that we convert the DynamicVal
285
308
// to an unknown string first and then refine it.
286
309
"dyn" : cty .UnknownVal (cty .String ).RefineNotNull (),
310
+
311
+ // This argument had a mark applied, which should be preserved
312
+ // despite the refinement.
313
+ "marked" : cty .UnknownVal (cty .String ).RefineNotNull ().Mark ("boop" ),
287
314
})
288
315
if diff := cmp .Diff (want , got , ctydebug .CmpOptions ); diff != "" {
289
316
t .Errorf ("wrong result\n %s" , diff )
0 commit comments