MCPcopy
hub / github.com/hashicorp/hcl / Value

Method Value

hclsyntax/expression.go:1312–1339  ·  view source on GitHub ↗
(ctx *hcl.EvalContext)

Source from the content-addressed store, hash-verified

1310}
1311
1312func (e *ObjectConsKeyExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
1313 // Because we accept a naked identifier as a literal key rather than a
1314 // reference, it's confusing to accept a traversal containing periods
1315 // here since we can't tell if the user intends to create a key with
1316 // periods or actually reference something. To avoid confusing downstream
1317 // errors we'll just prohibit a naked multi-step traversal here and
1318 // require the user to state their intent more clearly.
1319 // (This is handled at evaluation time rather than parse time because
1320 // an application using static analysis _can_ accept a naked multi-step
1321 // traversal here, if desired.)
1322 if !e.ForceNonLiteral {
1323 if travExpr, isTraversal := e.Wrapped.(*ScopeTraversalExpr); isTraversal && len(travExpr.Traversal) > 1 {
1324 var diags hcl.Diagnostics
1325 diags = append(diags, &hcl.Diagnostic{
1326 Severity: hcl.DiagError,
1327 Summary: "Ambiguous attribute key",
1328 Detail: "If this expression is intended to be a reference, wrap it in parentheses. If it's instead intended as a literal name containing periods, wrap it in quotes to create a string literal.",
1329 Subject: e.Range().Ptr(),
1330 })
1331 return cty.DynamicVal, diags
1332 }
1333
1334 if ln := e.literalName(); ln != "" {
1335 return cty.StringVal(ln), nil
1336 }
1337 }
1338 return e.Wrapped.Value(ctx)
1339}
1340
1341func (e *ObjectConsKeyExpr) Range() hcl.Range {
1342 return e.Wrapped.Range()

Callers

nothing calls this directly

Calls 4

RangeMethod · 0.95
literalNameMethod · 0.95
PtrMethod · 0.80
ValueMethod · 0.65

Tested by

no test coverage detected