Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decoder: Skip unknown tuple element #77

Merged
merged 1 commit into from
Aug 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion decoder/semantic_tokens.go
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,12 @@ func tokensForTupleConsExpr(expr *hclsyntax.TupleConsExpr, exprType cty.Type) []
elemType = *exprType.SetElementType()
}
if exprType.IsTupleType() {
elemType = exprType.TupleElementType(i)
elTypes := exprType.TupleElementTypes()
if len(elTypes) < i+1 {
// skip unknown tuple element
continue
}
elemType = elTypes[i]
}

tokens = append(tokens, tokenForTypedExpression(e, elemType)...)
Expand Down
62 changes: 62 additions & 0 deletions decoder/semantic_tokens_expr_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1172,6 +1172,68 @@ EOT
},
},
},
{
"undefined tuple expression",
map[string]*schema.AttributeSchema{
"attr": {
Expr: schema.ExprConstraints{
schema.TupleExpr{
Elems: []schema.ExprConstraints{},
},
},
},
},
`attr = [ "one" ]
`,
[]lang.SemanticToken{
{ // attr
Type: lang.TokenAttrName,
Modifiers: []lang.SemanticTokenModifier{},
Range: hcl.Range{
Filename: "test.tf",
Start: hcl.Pos{
Line: 1,
Column: 1,
Byte: 0,
},
End: hcl.Pos{
Line: 1,
Column: 5,
Byte: 4,
},
},
},
},
},
{
"undefined tuple type",
map[string]*schema.AttributeSchema{
"attr": {
Expr: schema.LiteralTypeOnly(cty.Tuple([]cty.Type{})),
},
},
`attr = [ "one" ]
`,
[]lang.SemanticToken{
{ // attr
Type: lang.TokenAttrName,
Modifiers: []lang.SemanticTokenModifier{},
Range: hcl.Range{
Filename: "test.tf",
Start: hcl.Pos{
Line: 1,
Column: 1,
Byte: 0,
},
End: hcl.Pos{
Line: 1,
Column: 5,
Byte: 4,
},
},
},
},
},
{
"tuple as list",
map[string]*schema.AttributeSchema{
Expand Down