@@ -12,7 +12,9 @@ import (
12
12
"github.com/google/go-cmp/cmp"
13
13
"github.com/hashicorp/hcl-lang/lang"
14
14
"github.com/hashicorp/hcl-lang/reference"
15
+ "github.com/hashicorp/hcl-lang/schema"
15
16
"github.com/hashicorp/hcl/v2"
17
+ "github.com/hashicorp/hcl/v2/hclsyntax"
16
18
"github.com/zclconf/go-cty-debug/ctydebug"
17
19
"github.com/zclconf/go-cty/cty"
18
20
)
@@ -352,3 +354,28 @@ func TestReferenceTargetForOriginAtPos(t *testing.T) {
352
354
})
353
355
}
354
356
}
357
+
358
+ func TestCollectReferenceTargets_nil_expr (t * testing.T ) {
359
+ // provider:: is not a traversal expression, so hcl will return a nil expression which needs to be
360
+ // handled gracefully
361
+ f , _ := hclsyntax .ParseConfig ([]byte (`attr = provider::` ), "test.tf" , hcl .InitialPos )
362
+
363
+ d := testPathDecoder (t , & PathContext {
364
+ Schema : & schema.BodySchema {
365
+ Attributes : map [string ]* schema.AttributeSchema {
366
+ "attr" : {Constraint : schema.AnyExpression {OfType : cty .DynamicPseudoType }},
367
+ },
368
+ },
369
+ Files : map [string ]* hcl.File {
370
+ "test.tf" : f ,
371
+ },
372
+ })
373
+ targets , err := d .CollectReferenceTargets ()
374
+ if err != nil {
375
+ t .Fatal ("unexpected error when collecting reference targets while there was no expr in one of them" )
376
+ }
377
+
378
+ if len (targets ) != 0 {
379
+ t .Fatalf ("expected no targets, got %d" , len (targets ))
380
+ }
381
+ }
0 commit comments