diff --git a/decoder/expr_list_ref_targets_test.go b/decoder/expr_list_ref_targets_test.go index 813b678d..78429e04 100644 --- a/decoder/expr_list_ref_targets_test.go +++ b/decoder/expr_list_ref_targets_test.go @@ -458,6 +458,73 @@ func TestCollectRefTargets_exprList_implied_hcl(t *testing.T) { }, }, }, + { + "declared as type", + &schema.BodySchema{ + Blocks: map[string]*schema.BlockSchema{ + "blk": { + Address: &schema.BlockAddrSchema{ + Steps: schema.Address{ + schema.StaticStep{Name: "blk"}, + }, + BodyAsData: true, + InferBody: true, + }, + Body: &schema.BodySchema{ + Attributes: map[string]*schema.AttributeSchema{ + "attr": { + Constraint: schema.List{ + Elem: schema.LiteralType{Type: cty.Bool}, + }, + IsOptional: true, + }, + }, + }, + }, + }, + }, + `blk { attr = [] }`, + reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 1, Byte: 0}, + End: hcl.Pos{Line: 1, Column: 18, Byte: 17}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 1, Byte: 0}, + End: hcl.Pos{Line: 1, Column: 4, Byte: 3}, + }, + Type: cty.Object(map[string]cty.Type{ + "attr": cty.List(cty.Bool), + }), + NestedTargets: reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + lang.AttrStep{Name: "attr"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 7, Byte: 6}, + End: hcl.Pos{Line: 1, Column: 16, Byte: 15}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 7, Byte: 6}, + End: hcl.Pos{Line: 1, Column: 11, Byte: 10}, + }, + Type: cty.List(cty.Bool), + NestedTargets: reference.Targets{}, + }, + }, + }, + }, + }, { "undeclared as reference", &schema.BodySchema{ @@ -1013,6 +1080,73 @@ func TestCollectRefTargets_exprList_implied_json(t *testing.T) { }, }, }, + { + "declared as type", + &schema.BodySchema{ + Blocks: map[string]*schema.BlockSchema{ + "blk": { + Address: &schema.BlockAddrSchema{ + Steps: schema.Address{ + schema.StaticStep{Name: "blk"}, + }, + BodyAsData: true, + InferBody: true, + }, + Body: &schema.BodySchema{ + Attributes: map[string]*schema.AttributeSchema{ + "attr": { + Constraint: schema.List{ + Elem: schema.LiteralType{Type: cty.Bool}, + }, + IsOptional: true, + }, + }, + }, + }, + }, + }, + `{"blk": {"attr": []}}`, + reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 9, Byte: 8}, + End: hcl.Pos{Line: 1, Column: 21, Byte: 20}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 9, Byte: 8}, + End: hcl.Pos{Line: 1, Column: 10, Byte: 9}, + }, + Type: cty.Object(map[string]cty.Type{ + "attr": cty.List(cty.Bool), + }), + NestedTargets: reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + lang.AttrStep{Name: "attr"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 10, Byte: 9}, + End: hcl.Pos{Line: 1, Column: 20, Byte: 19}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 10, Byte: 9}, + End: hcl.Pos{Line: 1, Column: 16, Byte: 15}, + }, + Type: cty.List(cty.Bool), + NestedTargets: reference.Targets{}, + }, + }, + }, + }, + }, { "undeclared as reference", &schema.BodySchema{ diff --git a/decoder/expr_map_ref_targets_test.go b/decoder/expr_map_ref_targets_test.go index fadecbc6..1f27f008 100644 --- a/decoder/expr_map_ref_targets_test.go +++ b/decoder/expr_map_ref_targets_test.go @@ -617,6 +617,73 @@ func TestCollectRefTargets_exprMap_implied_hcl(t *testing.T) { }, }, }, + { + "declared as type", + &schema.BodySchema{ + Blocks: map[string]*schema.BlockSchema{ + "blk": { + Address: &schema.BlockAddrSchema{ + Steps: schema.Address{ + schema.StaticStep{Name: "blk"}, + }, + BodyAsData: true, + InferBody: true, + }, + Body: &schema.BodySchema{ + Attributes: map[string]*schema.AttributeSchema{ + "attr": { + Constraint: schema.Map{ + Elem: schema.LiteralType{Type: cty.Bool}, + }, + IsOptional: true, + }, + }, + }, + }, + }, + }, + `blk { attr = {} }`, + reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 1, Byte: 0}, + End: hcl.Pos{Line: 1, Column: 18, Byte: 17}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 1, Byte: 0}, + End: hcl.Pos{Line: 1, Column: 4, Byte: 3}, + }, + Type: cty.Object(map[string]cty.Type{ + "attr": cty.Map(cty.Bool), + }), + NestedTargets: reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + lang.AttrStep{Name: "attr"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 7, Byte: 6}, + End: hcl.Pos{Line: 1, Column: 16, Byte: 15}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 7, Byte: 6}, + End: hcl.Pos{Line: 1, Column: 11, Byte: 10}, + }, + Type: cty.Map(cty.Bool), + NestedTargets: reference.Targets{}, + }, + }, + }, + }, + }, { "undeclared as reference", &schema.BodySchema{ @@ -1284,6 +1351,73 @@ func TestCollectRefTargets_exprMap_implied_json(t *testing.T) { }, }, }, + { + "declared as type", + &schema.BodySchema{ + Blocks: map[string]*schema.BlockSchema{ + "blk": { + Address: &schema.BlockAddrSchema{ + Steps: schema.Address{ + schema.StaticStep{Name: "blk"}, + }, + BodyAsData: true, + InferBody: true, + }, + Body: &schema.BodySchema{ + Attributes: map[string]*schema.AttributeSchema{ + "attr": { + Constraint: schema.Map{ + Elem: schema.LiteralType{Type: cty.Bool}, + }, + IsOptional: true, + }, + }, + }, + }, + }, + }, + `{"blk": {"attr": {}}}`, + reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 9, Byte: 8}, + End: hcl.Pos{Line: 1, Column: 21, Byte: 20}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 9, Byte: 8}, + End: hcl.Pos{Line: 1, Column: 10, Byte: 9}, + }, + Type: cty.Object(map[string]cty.Type{ + "attr": cty.Map(cty.Bool), + }), + NestedTargets: reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + lang.AttrStep{Name: "attr"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 10, Byte: 9}, + End: hcl.Pos{Line: 1, Column: 20, Byte: 19}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 10, Byte: 9}, + End: hcl.Pos{Line: 1, Column: 16, Byte: 15}, + }, + Type: cty.Map(cty.Bool), + NestedTargets: reference.Targets{}, + }, + }, + }, + }, + }, { "undeclared as reference", &schema.BodySchema{ diff --git a/decoder/expr_object_ref_targets_test.go b/decoder/expr_object_ref_targets_test.go index 284d1492..a4012c12 100644 --- a/decoder/expr_object_ref_targets_test.go +++ b/decoder/expr_object_ref_targets_test.go @@ -776,6 +776,93 @@ func TestCollectRefTargets_exprObject_implied_hcl(t *testing.T) { }, }, }, + { + "declared as type", + &schema.BodySchema{ + Blocks: map[string]*schema.BlockSchema{ + "blk": { + Address: &schema.BlockAddrSchema{ + Steps: schema.Address{ + schema.StaticStep{Name: "blk"}, + }, + BodyAsData: true, + InferBody: true, + }, + Body: &schema.BodySchema{ + Attributes: map[string]*schema.AttributeSchema{ + "attr": { + Constraint: schema.Object{ + Attributes: schema.ObjectAttributes{ + "foo": {Constraint: schema.LiteralType{Type: cty.Bool}}, + }, + }, + IsOptional: true, + }, + }, + }, + }, + }, + }, + `blk { attr = {} }`, + reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 1, Byte: 0}, + End: hcl.Pos{Line: 1, Column: 18, Byte: 17}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 1, Byte: 0}, + End: hcl.Pos{Line: 1, Column: 4, Byte: 3}, + }, + Type: cty.Object(map[string]cty.Type{ + "attr": cty.Object(map[string]cty.Type{ + "foo": cty.Bool, + }), + }), + NestedTargets: reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + lang.AttrStep{Name: "attr"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 7, Byte: 6}, + End: hcl.Pos{Line: 1, Column: 16, Byte: 15}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 7, Byte: 6}, + End: hcl.Pos{Line: 1, Column: 11, Byte: 10}, + }, + Type: cty.Object(map[string]cty.Type{ + "foo": cty.Bool, + }), + NestedTargets: reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + lang.AttrStep{Name: "attr"}, + lang.AttrStep{Name: "foo"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 14, Byte: 13}, + End: hcl.Pos{Line: 1, Column: 14, Byte: 13}, + }, + Type: cty.Bool, + }, + }, + }, + }, + }, + }, + }, { "undeclared as reference", &schema.BodySchema{ @@ -1606,6 +1693,95 @@ func TestCollectRefTargets_exprObject_implied_json(t *testing.T) { }, }, }, + { + "declared as type", + &schema.BodySchema{ + Blocks: map[string]*schema.BlockSchema{ + "blk": { + Address: &schema.BlockAddrSchema{ + Steps: schema.Address{ + schema.StaticStep{Name: "blk"}, + }, + BodyAsData: true, + InferBody: true, + }, + Body: &schema.BodySchema{ + Attributes: map[string]*schema.AttributeSchema{ + "attr": { + Constraint: schema.Object{ + Attributes: map[string]*schema.AttributeSchema{ + "foo": { + Constraint: schema.LiteralType{Type: cty.Bool}, + }, + }, + }, + IsOptional: true, + }, + }, + }, + }, + }, + }, + `{"blk": {"attr": {}}}`, + reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 9, Byte: 8}, + End: hcl.Pos{Line: 1, Column: 21, Byte: 20}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 9, Byte: 8}, + End: hcl.Pos{Line: 1, Column: 10, Byte: 9}, + }, + Type: cty.Object(map[string]cty.Type{ + "attr": cty.Object(map[string]cty.Type{ + "foo": cty.Bool, + }), + }), + NestedTargets: reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + lang.AttrStep{Name: "attr"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 10, Byte: 9}, + End: hcl.Pos{Line: 1, Column: 20, Byte: 19}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 10, Byte: 9}, + End: hcl.Pos{Line: 1, Column: 16, Byte: 15}, + }, + Type: cty.Object(map[string]cty.Type{ + "foo": cty.Bool, + }), + NestedTargets: reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + lang.AttrStep{Name: "attr"}, + lang.AttrStep{Name: "foo"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 18, Byte: 17}, + End: hcl.Pos{Line: 1, Column: 18, Byte: 17}, + }, + Type: cty.Bool, + }, + }, + }, + }, + }, + }, + }, { "undeclared as reference", &schema.BodySchema{ diff --git a/decoder/expr_set_ref_targets_test.go b/decoder/expr_set_ref_targets_test.go index 39415a8c..ef3daf09 100644 --- a/decoder/expr_set_ref_targets_test.go +++ b/decoder/expr_set_ref_targets_test.go @@ -353,6 +353,73 @@ func TestCollectRefTargets_exprSet_implied_hcl(t *testing.T) { }, }, }, + { + "declared as type", + &schema.BodySchema{ + Blocks: map[string]*schema.BlockSchema{ + "blk": { + Address: &schema.BlockAddrSchema{ + Steps: schema.Address{ + schema.StaticStep{Name: "blk"}, + }, + BodyAsData: true, + InferBody: true, + }, + Body: &schema.BodySchema{ + Attributes: map[string]*schema.AttributeSchema{ + "attr": { + Constraint: schema.Set{ + Elem: schema.LiteralType{Type: cty.Bool}, + }, + IsOptional: true, + }, + }, + }, + }, + }, + }, + `blk { attr = [] }`, + reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 1, Byte: 0}, + End: hcl.Pos{Line: 1, Column: 18, Byte: 17}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 1, Byte: 0}, + End: hcl.Pos{Line: 1, Column: 4, Byte: 3}, + }, + Type: cty.Object(map[string]cty.Type{ + "attr": cty.Set(cty.Bool), + }), + NestedTargets: reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + lang.AttrStep{Name: "attr"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 7, Byte: 6}, + End: hcl.Pos{Line: 1, Column: 16, Byte: 15}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 7, Byte: 6}, + End: hcl.Pos{Line: 1, Column: 11, Byte: 10}, + }, + Type: cty.Set(cty.Bool), + NestedTargets: reference.Targets{}, + }, + }, + }, + }, + }, { "undeclared as reference", &schema.BodySchema{ @@ -765,6 +832,73 @@ func TestCollectRefTargets_exprSet_implied_json(t *testing.T) { }, }, }, + { + "declared as type", + &schema.BodySchema{ + Blocks: map[string]*schema.BlockSchema{ + "blk": { + Address: &schema.BlockAddrSchema{ + Steps: schema.Address{ + schema.StaticStep{Name: "blk"}, + }, + BodyAsData: true, + InferBody: true, + }, + Body: &schema.BodySchema{ + Attributes: map[string]*schema.AttributeSchema{ + "attr": { + Constraint: schema.Set{ + Elem: schema.LiteralType{Type: cty.Bool}, + }, + IsOptional: true, + }, + }, + }, + }, + }, + }, + `{"blk": {"attr": []}}`, + reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 9, Byte: 8}, + End: hcl.Pos{Line: 1, Column: 21, Byte: 20}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 9, Byte: 8}, + End: hcl.Pos{Line: 1, Column: 10, Byte: 9}, + }, + Type: cty.Object(map[string]cty.Type{ + "attr": cty.Set(cty.Bool), + }), + NestedTargets: reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + lang.AttrStep{Name: "attr"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 10, Byte: 9}, + End: hcl.Pos{Line: 1, Column: 20, Byte: 19}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 10, Byte: 9}, + End: hcl.Pos{Line: 1, Column: 16, Byte: 15}, + }, + Type: cty.Set(cty.Bool), + NestedTargets: reference.Targets{}, + }, + }, + }, + }, + }, { "undeclared as reference", &schema.BodySchema{ diff --git a/decoder/expr_tuple_ref_targets_test.go b/decoder/expr_tuple_ref_targets_test.go index 4dada34c..caf64a67 100644 --- a/decoder/expr_tuple_ref_targets_test.go +++ b/decoder/expr_tuple_ref_targets_test.go @@ -592,6 +592,89 @@ func TestCollectRefTargets_exprTuple_implied_hcl(t *testing.T) { }, }, }, + { + "declared as type", + &schema.BodySchema{ + Blocks: map[string]*schema.BlockSchema{ + "blk": { + Address: &schema.BlockAddrSchema{ + Steps: schema.Address{ + schema.StaticStep{Name: "blk"}, + }, + BodyAsData: true, + InferBody: true, + }, + Body: &schema.BodySchema{ + Attributes: map[string]*schema.AttributeSchema{ + "attr": { + Constraint: schema.Tuple{ + Elems: []schema.Constraint{ + schema.LiteralType{Type: cty.Bool}, + }, + }, + IsOptional: true, + }, + }, + }, + }, + }, + }, + `blk { attr = [] }`, + reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 1, Byte: 0}, + End: hcl.Pos{Line: 1, Column: 18, Byte: 17}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 1, Byte: 0}, + End: hcl.Pos{Line: 1, Column: 4, Byte: 3}, + }, + Type: cty.Object(map[string]cty.Type{ + "attr": cty.Tuple([]cty.Type{cty.Bool}), + }), + NestedTargets: reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + lang.AttrStep{Name: "attr"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 7, Byte: 6}, + End: hcl.Pos{Line: 1, Column: 16, Byte: 15}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 7, Byte: 6}, + End: hcl.Pos{Line: 1, Column: 11, Byte: 10}, + }, + Type: cty.Tuple([]cty.Type{cty.Bool}), + NestedTargets: reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + lang.AttrStep{Name: "attr"}, + lang.IndexStep{Key: cty.NumberIntVal(0)}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl", + Start: hcl.Pos{Line: 1, Column: 14, Byte: 13}, + End: hcl.Pos{Line: 1, Column: 14, Byte: 13}, + }, + Type: cty.Bool, + }, + }, + }, + }, + }, + }, + }, { "undeclared as reference", &schema.BodySchema{ @@ -1176,6 +1259,89 @@ func TestCollectRefTargets_exprTuple_implied_json(t *testing.T) { }, }, }, + { + "declared as type", + &schema.BodySchema{ + Blocks: map[string]*schema.BlockSchema{ + "blk": { + Address: &schema.BlockAddrSchema{ + Steps: schema.Address{ + schema.StaticStep{Name: "blk"}, + }, + BodyAsData: true, + InferBody: true, + }, + Body: &schema.BodySchema{ + Attributes: map[string]*schema.AttributeSchema{ + "attr": { + Constraint: schema.Tuple{ + Elems: []schema.Constraint{ + schema.LiteralType{Type: cty.Bool}, + }, + }, + IsOptional: true, + }, + }, + }, + }, + }, + }, + `{"blk": {"attr": []}}`, + reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 9, Byte: 8}, + End: hcl.Pos{Line: 1, Column: 21, Byte: 20}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 9, Byte: 8}, + End: hcl.Pos{Line: 1, Column: 10, Byte: 9}, + }, + Type: cty.Object(map[string]cty.Type{ + "attr": cty.Tuple([]cty.Type{cty.Bool}), + }), + NestedTargets: reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + lang.AttrStep{Name: "attr"}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 10, Byte: 9}, + End: hcl.Pos{Line: 1, Column: 20, Byte: 19}, + }, + DefRangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 10, Byte: 9}, + End: hcl.Pos{Line: 1, Column: 16, Byte: 15}, + }, + Type: cty.Tuple([]cty.Type{cty.Bool}), + NestedTargets: reference.Targets{ + { + Addr: lang.Address{ + lang.RootStep{Name: "blk"}, + lang.AttrStep{Name: "attr"}, + lang.IndexStep{Key: cty.NumberIntVal(0)}, + }, + RangePtr: &hcl.Range{ + Filename: "test.hcl.json", + Start: hcl.Pos{Line: 1, Column: 18, Byte: 17}, + End: hcl.Pos{Line: 1, Column: 18, Byte: 17}, + }, + Type: cty.Bool, + }, + }, + }, + }, + }, + }, + }, { "undeclared as reference", &schema.BodySchema{ diff --git a/decoder/reference_targets.go b/decoder/reference_targets.go index 883bf85f..4ff1bec0 100644 --- a/decoder/reference_targets.go +++ b/decoder/reference_targets.go @@ -721,28 +721,29 @@ func (d *PathDecoder) collectInferredReferenceTargetsForBody(addr lang.Address, for name, aSchema := range bodySchema.Attributes { var attrType cty.Type if aSchema.Constraint != nil { - var ok bool + cons, ok := aSchema.Constraint.(schema.TypeAwareConstraint) + if ok { + typ, ok := cons.ConstraintType() + if ok { + attrType = typ + } + } + rawAttr, ok := rawAttributes[name] if ok { // try to infer type if attribute is declared expr, ok := newExpression(d.pathCtx, rawAttr.Expr, aSchema.Constraint).(CanInferTypeExpression) - if !ok { - continue - } - attrType, ok = expr.InferType() - if !ok { - continue - } - } else { - cons, ok := aSchema.Constraint.(schema.TypeAwareConstraint) - if !ok { - continue - } - attrType, ok = cons.ConstraintType() - if !ok { - continue + if ok { + typ, ok := expr.InferType() + if ok { + attrType = typ + } } } + + if attrType == cty.NilType { + continue + } } else { var ok bool attrType, ok = exprConstraintToDataType(aSchema.Expr)