zclsyntax: specific error message for nested attr-only splat

Attribute-only splat expressions cannot have other splats nested inside,
since we're only interested in supporting how these behaved for HIL when
running inside Hashicorp Terraform. More complex cases should be dealt
with using either full splats (bracketed *) or "for" expressions.
This commit is contained in:
Martin Atkins 2017-06-16 08:39:28 -07:00
parent 22bc5ce5c6
commit d90da0c4ba
2 changed files with 24 additions and 6 deletions

View File

@ -529,6 +529,15 @@ upper(
cty.StringVal("Steve"),
0,
},
{
`[["hello"], ["goodbye"]].*.*`,
nil,
cty.TupleVal([]cty.Value{
cty.TupleVal([]cty.Value{cty.StringVal("hello")}),
cty.TupleVal([]cty.Value{cty.StringVal("goodbye")}),
}),
1,
},
{
`["hello"][0]`,

View File

@ -512,12 +512,21 @@ Traversal:
dot := p.Read()
if p.Peek().Type != TokenIdent {
if !p.recovery {
diags = append(diags, &zcl.Diagnostic{
Severity: zcl.DiagError,
Summary: "Invalid attribute name",
Detail: "An attribute name is required after a dot.",
Subject: &attrTok.Range,
})
if p.Peek().Type == TokenStar {
diags = append(diags, &zcl.Diagnostic{
Severity: zcl.DiagError,
Summary: "Nested splat expression not allowed",
Detail: "A splat expression (*) cannot be used inside another attribute-only splat expression.",
Subject: p.Peek().Range.Ptr(),
})
} else {
diags = append(diags, &zcl.Diagnostic{
Severity: zcl.DiagError,
Summary: "Invalid attribute name",
Detail: "An attribute name is required after a dot.",
Subject: &attrTok.Range,
})
}
}
p.setRecovery()
continue Traversal