Merge pull request #2392 from crazy-max/update-hcl

vendor: update hcl dependencies
This commit is contained in:
CrazyMax 2024-04-10 08:48:10 +02:00 committed by GitHub
commit a9575a872a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
25 changed files with 909 additions and 629 deletions

4
go.mod
View File

@ -24,7 +24,7 @@ require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/google/uuid v1.6.0
github.com/hashicorp/go-cty-funcs v0.0.0-20230405223818-a090f58aa992
github.com/hashicorp/hcl/v2 v2.19.1
github.com/hashicorp/hcl/v2 v2.20.1
github.com/in-toto/in-toto-golang v0.5.0
github.com/moby/buildkit v0.13.0-rc3.0.20240328152707-25bec7145b39 // v0.14.0-dev
github.com/moby/sys/mountinfo v0.7.1
@ -40,7 +40,7 @@ require (
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.8.4
github.com/tonistiigi/fsutil v0.0.0-20240301111122-7525a1af2bb5
github.com/zclconf/go-cty v1.14.1
github.com/zclconf/go-cty v1.14.4
go.opentelemetry.io/otel v1.21.0
go.opentelemetry.io/otel/metric v1.21.0
go.opentelemetry.io/otel/trace v1.21.0

14
go.sum
View File

@ -244,8 +244,8 @@ github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9n
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
github.com/hashicorp/go-cty-funcs v0.0.0-20230405223818-a090f58aa992 h1:fYOrSfO5C9PmFGtmRWSYGqq52SOoE2dXMtAn2Xzh1LQ=
github.com/hashicorp/go-cty-funcs v0.0.0-20230405223818-a090f58aa992/go.mod h1:Abjk0jbRkDaNCzsRhOv2iDCofYpX1eVsjozoiK63qLA=
github.com/hashicorp/hcl/v2 v2.19.1 h1://i05Jqznmb2EXqa39Nsvyan2o5XyMowW5fnCKW5RPI=
github.com/hashicorp/hcl/v2 v2.19.1/go.mod h1:ThLC89FV4p9MPW804KVbe/cEXoQ8NZEh+JtMeeGErHE=
github.com/hashicorp/hcl/v2 v2.20.1 h1:M6hgdyz7HYt1UN9e61j+qKJBqR3orTWbI1HKBJEdxtc=
github.com/hashicorp/hcl/v2 v2.20.1/go.mod h1:TZDqQ4kNKCbh1iJp99FdPiUaVDDUPivbqxZulxDYqL4=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
github.com/imdario/mergo v0.3.16/go.mod h1:WBLT9ZmE3lPoWsEzCh9LPo3TiwVN+ZKEjmz+hD27ysY=
@ -282,8 +282,6 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/lib/pq v0.0.0-20150723085316-0dad96c0b94f/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo=
github.com/magiconair/properties v1.5.3 h1:C8fxWnhYyME3n0klPOhVM7PtYUB3eV1W3DeFmN3j53Y=
github.com/magiconair/properties v1.5.3/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
@ -404,8 +402,6 @@ github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncj
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/secure-systems-lab/go-securesystemslib v0.4.0 h1:b23VGrQhTA8cN2CbBw7/FulN9fTtqYUdS5+Oxzt+DUE=
github.com/secure-systems-lab/go-securesystemslib v0.4.0/go.mod h1:FGBZgq2tXWICsxWQW1msNf49F0Pf2Op5Htayx335Qbs=
github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ=
github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo=
github.com/serialx/hashring v0.0.0-20200727003509-22c0c7ab6b1b h1:h+3JX2VoWTFuyQEo87pStk/a99dzIO1mM9KxIyLPGTU=
github.com/serialx/hashring v0.0.0-20200727003509-22c0c7ab6b1b/go.mod h1:/yeG0My1xr/u+HZrFQ1tOQQQQrOawfyMUH13ai5brBc=
github.com/shibumi/go-pathspec v1.3.0 h1:QUyMZhFo0Md5B8zV8x2tesohbb5kfbpTi9rBnKh5dkI=
@ -466,8 +462,10 @@ github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQ
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/zclconf/go-cty v1.4.0/go.mod h1:nHzOclRkoj++EU9ZjSrZvRG0BXIWt8c7loYc0qXAFGQ=
github.com/zclconf/go-cty v1.14.1 h1:t9fyA35fwjjUMcmL5hLER+e/rEPqrbCK1/OSE4SI9KA=
github.com/zclconf/go-cty v1.14.1/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
github.com/zclconf/go-cty v1.14.4 h1:uXXczd9QDGsgu0i/QFR/hzI5NYCHLf6NQw/atrbnhq8=
github.com/zclconf/go-cty v1.14.4/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b h1:FosyBZYxY34Wul7O/MSKey3txpPYyCqVO5ZyceuQJEI=
github.com/zclconf/go-cty-debug v0.0.0-20191215020915-b22d67c1ba0b/go.mod h1:ZRKQfBXbGkpdV6QMzT3rU1kSTAnfu1dO8dPKjYprgj8=
go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0=
go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo=
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.1 h1:SpGay3w+nEwMpfVnbqOLH5gY52/foP8RE8UzTZ1pdSE=

View File

@ -1,5 +1,25 @@
# HCL Changelog
## v2.20.1 (March 26, 2024)
### Bugs Fixed
* Return `ExprSyntaxError` when an invalid namespaced function is encountered during parsing ([#668](https://github.com/hashicorp/hcl/pull/668))
### Internal
* Standardize on only two value dumping/diffing libraries ([#669](https://github.com/hashicorp/hcl/pull/669))
## v2.20.0 (February 29, 2024)
### Enhancements
* Support for namespaced functions ([#639](https://github.com/hashicorp/hcl/pull/639))
### Bugs Fixed
* ext/dynblock: if `iterator` is invalid return this error instead of consequential errors ([#656](https://github.com/hashicorp/hcl/pull/656))
## v2.19.0 (October 16, 2023)
### Enhancements
@ -43,7 +63,7 @@
* HCL now uses a newer version of the upstream `cty` library which has improved treatment of unknown values: it can now track additional optional information that reduces the range of an unknown value, which allows some operations against unknown values to return known or partially-known results. ([#590](https://github.com/hashicorp/hcl/pull/590))
**Note:** This change effectively passes on [`cty`'s notion of backward compatibility](https://github.com/zclconf/go-cty/blob/main/COMPATIBILITY.md) whereby unknown values can become "more known" in later releases. In particular, if your caller is using `cty.Value.RawEquals` in its tests against the results of operations with unknown values then you may see those tests begin failing after upgrading, due to the values now being more "refined".
If so, you should review the refinements with consideration to [the `cty` refinements docs](https://github.com/zclconf/go-cty/blob/7dcbae46a6f247e983efb1fa774d2bb68781a333/docs/refinements.md) and update your expected results to match only if the reported refinements seem correct for the given situation. The `RawEquals` method is intended only for making exact value comparisons in test cases, so main application code should not use it; use `Equals` instead for real logic, which will take refinements into account automatically.
## v2.16.2 (March 9, 2023)
@ -173,7 +193,7 @@
* hclsyntax: Mark objects with keys that are sensitive. ([#440](https://github.com/hashicorp/hcl/pull/440))
## v2.8.1 (December 17, 2020)
### Bugs Fixed
* hclsyntax: Fix panic when expanding marked function arguments. ([#429](https://github.com/hashicorp/hcl/pull/429))

18
vendor/github.com/hashicorp/hcl/v2/Makefile generated vendored Normal file
View File

@ -0,0 +1,18 @@
fmtcheck:
"$(CURDIR)/scripts/gofmtcheck.sh"
fmtfix:
gofmt -w ./
vetcheck:
go vet ./...
copyrightcheck:
go run github.com/hashicorp/copywrite@latest headers --plan
copyrightfix:
go run github.com/hashicorp/copywrite@latest headers
check: copyrightcheck vetcheck fmtcheck
fix: copyrightfix fmtfix

View File

@ -6,6 +6,7 @@ package hclsyntax
import (
"fmt"
"sort"
"strings"
"sync"
"github.com/hashicorp/hcl/v2"
@ -251,6 +252,76 @@ func (e *FunctionCallExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnosti
}
}
extraUnknown := &functionCallUnknown{
name: e.Name,
}
// For historical reasons, we represent namespaced function names
// as strings with :: separating the names. If this was an attempt
// to call a namespaced function then we'll try to distinguish
// between an invalid namespace or an invalid name within a valid
// namespace in order to give the user better feedback about what
// is wrong.
//
// The parser guarantees that a function name will always
// be a series of valid identifiers separated by "::" with no
// other content, so we can be relatively unforgiving in our processing
// here.
if sepIdx := strings.LastIndex(e.Name, "::"); sepIdx != -1 {
namespace := e.Name[:sepIdx+2]
name := e.Name[sepIdx+2:]
avail := make([]string, 0, len(ctx.Functions))
for availName := range ctx.Functions {
if strings.HasPrefix(availName, namespace) {
avail = append(avail, availName)
}
}
extraUnknown.name = name
extraUnknown.namespace = namespace
if len(avail) == 0 {
// TODO: Maybe use nameSuggestion for the other available
// namespaces? But that'd require us to go scan the function
// table again, so we'll wait to see if it's really warranted.
// For now, we're assuming people are more likely to misremember
// the function names than the namespaces, because in many
// applications there will be relatively few namespaces compared
// to the number of distinct functions.
return cty.DynamicVal, hcl.Diagnostics{
{
Severity: hcl.DiagError,
Summary: "Call to unknown function",
Detail: fmt.Sprintf("There are no functions in namespace %q.", namespace),
Subject: &e.NameRange,
Context: e.Range().Ptr(),
Expression: e,
EvalContext: ctx,
Extra: extraUnknown,
},
}
} else {
suggestion := nameSuggestion(name, avail)
if suggestion != "" {
suggestion = fmt.Sprintf(" Did you mean %s%s?", namespace, suggestion)
}
return cty.DynamicVal, hcl.Diagnostics{
{
Severity: hcl.DiagError,
Summary: "Call to unknown function",
Detail: fmt.Sprintf("There is no function named %q in namespace %s.%s", name, namespace, suggestion),
Subject: &e.NameRange,
Context: e.Range().Ptr(),
Expression: e,
EvalContext: ctx,
Extra: extraUnknown,
},
}
}
}
avail := make([]string, 0, len(ctx.Functions))
for name := range ctx.Functions {
avail = append(avail, name)
@ -269,6 +340,7 @@ func (e *FunctionCallExpr) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnosti
Context: e.Range().Ptr(),
Expression: e,
EvalContext: ctx,
Extra: extraUnknown,
},
}
}
@ -616,6 +688,27 @@ func (e *functionCallDiagExtra) FunctionCallError() error {
return e.functionCallError
}
// FunctionCallUnknownDiagExtra is an interface implemented by a value in the Extra
// field of some diagnostics to indicate when the error was caused by a call to
// an unknown function.
type FunctionCallUnknownDiagExtra interface {
CalledFunctionName() string
CalledFunctionNamespace() string
}
type functionCallUnknown struct {
name string
namespace string
}
func (e *functionCallUnknown) CalledFunctionName() string {
return e.name
}
func (e *functionCallUnknown) CalledFunctionNamespace() string {
return e.namespace
}
type ConditionalExpr struct {
Condition Expression
TrueResult Expression
@ -1920,3 +2013,27 @@ func (e *AnonSymbolExpr) Range() hcl.Range {
func (e *AnonSymbolExpr) StartRange() hcl.Range {
return e.SrcRange
}
// ExprSyntaxError is a placeholder for an invalid expression that could not
// be parsed due to syntax errors.
type ExprSyntaxError struct {
Placeholder cty.Value
ParseDiags hcl.Diagnostics
SrcRange hcl.Range
}
func (e *ExprSyntaxError) Value(ctx *hcl.EvalContext) (cty.Value, hcl.Diagnostics) {
return e.Placeholder, e.ParseDiags
}
func (e *ExprSyntaxError) walkChildNodes(w internalWalkFunc) {
// ExprSyntaxError is a leaf node in the tree
}
func (e *ExprSyntaxError) Range() hcl.Range {
return e.SrcRange
}
func (e *ExprSyntaxError) StartRange() hcl.Range {
return e.SrcRange
}

View File

@ -3,7 +3,7 @@
package hclsyntax
// Generated by expression_vars_get.go. DO NOT EDIT.
// Generated by expression_vars_gen.go. DO NOT EDIT.
// Run 'go generate' on this package to update the set of functions here.
import (
@ -22,6 +22,10 @@ func (e *ConditionalExpr) Variables() []hcl.Traversal {
return Variables(e)
}
func (e *ExprSyntaxError) Variables() []hcl.Traversal {
return Variables(e)
}
func (e *ForExpr) Variables() []hcl.Traversal {
return Variables(e)
}

View File

@ -9,4 +9,4 @@ package hclsyntax
//go:generate gofmt -w scan_tokens.go
//go:generate ragel -Z scan_string_lit.rl
//go:generate gofmt -w scan_string_lit.go
//go:generate stringer -type TokenType -output token_type_string.go
//go:generate go run golang.org/x/tools/cmd/stringer -type TokenType -output token_type_string.go

View File

@ -999,7 +999,7 @@ func (p *parser) parseExpressionTerm() (Expression, hcl.Diagnostics) {
case TokenIdent:
tok := p.Read() // eat identifier token
if p.Peek().Type == TokenOParen {
if p.Peek().Type == TokenOParen || p.Peek().Type == TokenDoubleColon {
return p.finishParsingFunctionCall(tok)
}
@ -1145,16 +1145,76 @@ func (p *parser) numberLitValue(tok Token) (cty.Value, hcl.Diagnostics) {
// finishParsingFunctionCall parses a function call assuming that the function
// name was already read, and so the peeker should be pointing at the opening
// parenthesis after the name.
// parenthesis after the name, or at the double-colon after the initial
// function scope name.
func (p *parser) finishParsingFunctionCall(name Token) (Expression, hcl.Diagnostics) {
var diags hcl.Diagnostics
openTok := p.Read()
if openTok.Type != TokenOParen {
if openTok.Type != TokenOParen && openTok.Type != TokenDoubleColon {
// should never happen if callers behave
panic("finishParsingFunctionCall called with non-parenthesis as next token")
panic("finishParsingFunctionCall called with unsupported next token")
}
nameStr := string(name.Bytes)
nameEndPos := name.Range.End
for openTok.Type == TokenDoubleColon {
nextName := p.Read()
if nextName.Type != TokenIdent {
diag := hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Missing function name",
Detail: "Function scope resolution symbol :: must be followed by a function name in this scope.",
Subject: &nextName.Range,
Context: hcl.RangeBetween(name.Range, nextName.Range).Ptr(),
}
diags = append(diags, &diag)
p.recoverOver(TokenOParen)
return &ExprSyntaxError{
ParseDiags: hcl.Diagnostics{&diag},
Placeholder: cty.DynamicVal,
SrcRange: hcl.RangeBetween(name.Range, nextName.Range),
}, diags
}
// Initial versions of HCLv2 didn't support function namespaces, and
// so for backward compatibility we just treat namespaced functions
// as weird names with "::" separators in them, saved as a string
// to keep the API unchanged. FunctionCallExpr also has some special
// handling of names containing :: when referring to a function that
// doesn't exist in EvalContext, to return better error messages
// when namespaces are used incorrectly.
nameStr = nameStr + "::" + string(nextName.Bytes)
nameEndPos = nextName.Range.End
openTok = p.Read()
}
nameRange := hcl.Range{
Filename: name.Range.Filename,
Start: name.Range.Start,
End: nameEndPos,
}
if openTok.Type != TokenOParen {
diag := hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Missing open parenthesis",
Detail: "Function selector must be followed by an open parenthesis to begin the function call.",
Subject: &openTok.Range,
Context: hcl.RangeBetween(name.Range, openTok.Range).Ptr(),
}
diags = append(diags, &diag)
p.recoverOver(TokenOParen)
return &ExprSyntaxError{
ParseDiags: hcl.Diagnostics{&diag},
Placeholder: cty.DynamicVal,
SrcRange: hcl.RangeBetween(name.Range, openTok.Range),
}, diags
}
var args []Expression
var diags hcl.Diagnostics
var expandFinal bool
var closeTok Token
@ -1218,7 +1278,7 @@ Token:
diags = append(diags, &hcl.Diagnostic{
Severity: hcl.DiagError,
Summary: "Unterminated function call",
Detail: "There is no closing parenthesis for this function call before the end of the file. This may be caused by incorrect parethesis nesting elsewhere in this file.",
Detail: "There is no closing parenthesis for this function call before the end of the file. This may be caused by incorrect parenthesis nesting elsewhere in this file.",
Subject: hcl.RangeBetween(name.Range, openTok.Range).Ptr(),
})
default:
@ -1245,12 +1305,12 @@ Token:
p.PopIncludeNewlines()
return &FunctionCallExpr{
Name: string(name.Bytes),
Name: nameStr,
Args: args,
ExpandFinal: expandFinal,
NameRange: name.Range,
NameRange: nameRange,
OpenParenRange: openTok.Range,
CloseParenRange: closeTok.Range,
}, diags

View File

@ -1,13 +1,12 @@
//line scan_string_lit.rl:1
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
//line scan_string_lit.rl:1
package hclsyntax
// This file is generated from scan_string_lit.rl. DO NOT EDIT.
//line scan_string_lit.go:9
//line scan_string_lit.go:11
var _hclstrtok_actions []byte = []byte{
0, 1, 0, 1, 1, 2, 1, 0,
}
@ -117,12 +116,12 @@ const hclstrtok_error int = 0
const hclstrtok_en_quoted int = 10
const hclstrtok_en_unquoted int = 4
//line scan_string_lit.rl:10
//line scan_string_lit.rl:12
func scanStringLit(data []byte, quoted bool) [][]byte {
var ret [][]byte
//line scan_string_lit.rl:61
//line scan_string_lit.rl:63
// Ragel state
p := 0 // "Pointer" into data
@ -147,11 +146,11 @@ func scanStringLit(data []byte, quoted bool) [][]byte {
ret = append(ret, data[ts:te])
}*/
//line scan_string_lit.go:154
//line scan_string_lit.go:156
{
}
//line scan_string_lit.go:158
//line scan_string_lit.go:160
{
var _klen int
var _trans int
@ -232,7 +231,7 @@ func scanStringLit(data []byte, quoted bool) [][]byte {
_acts++
switch _hclstrtok_actions[_acts-1] {
case 0:
//line scan_string_lit.rl:40
//line scan_string_lit.rl:42
// If te is behind p then we've skipped over some literal
// characters which we must now return.
@ -242,12 +241,12 @@ func scanStringLit(data []byte, quoted bool) [][]byte {
ts = p
case 1:
//line scan_string_lit.rl:48
//line scan_string_lit.rl:50
te = p
ret = append(ret, data[ts:te])
//line scan_string_lit.go:253
//line scan_string_lit.go:255
}
}
@ -270,12 +269,12 @@ func scanStringLit(data []byte, quoted bool) [][]byte {
__acts++
switch _hclstrtok_actions[__acts-1] {
case 1:
//line scan_string_lit.rl:48
//line scan_string_lit.rl:50
te = p
ret = append(ret, data[ts:te])
//line scan_string_lit.go:278
//line scan_string_lit.go:280
}
}
}
@ -285,7 +284,7 @@ func scanStringLit(data []byte, quoted bool) [][]byte {
}
}
//line scan_string_lit.rl:89
//line scan_string_lit.rl:91
if te < p {
// Collect any leftover literal characters at the end of the input

View File

@ -1,3 +1,5 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package hclsyntax

File diff suppressed because it is too large Load Diff

View File

@ -1,3 +1,5 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package hclsyntax
@ -53,6 +55,7 @@ func scanTokens(data []byte, filename string, start hcl.Pos, mode scanMode) []To
LogicalAnd = "&&";
LogicalOr = "||";
DoubleColon = "::";
Ellipsis = "...";
FatArrow = "=>";
@ -294,6 +297,7 @@ func scanTokens(data []byte, filename string, start hcl.Pos, mode scanMode) []To
LessThanEqual => { token(TokenLessThanEq); };
LogicalAnd => { token(TokenAnd); };
LogicalOr => { token(TokenOr); };
DoubleColon => { token(TokenDoubleColon); };
Ellipsis => { token(TokenEllipsis); };
FatArrow => { token(TokenFatArrow); };
SelfToken => { selfToken() };

View File

@ -668,7 +668,7 @@ a == b equal
a != b not equal
```
Two values are equal if the are of identical types and their values are
Two values are equal if they are of identical types and their values are
equal as defined in the HCL syntax-agnostic information model. The equality
operators are commutative and opposite, such that `(a == b) == !(a != b)`
and `(a == b) == (b == a)` for all values `a` and `b`.

View File

@ -63,8 +63,9 @@ const (
TokenDot TokenType = '.'
TokenComma TokenType = ','
TokenEllipsis TokenType = '…'
TokenFatArrow TokenType = '⇒'
TokenDoubleColon TokenType = '⸬'
TokenEllipsis TokenType = '…'
TokenFatArrow TokenType = '⇒'
TokenQuestion TokenType = '?'
TokenColon TokenType = ':'

View File

@ -1,11 +1,11 @@
// Code generated by "stringer -type TokenType -output token_type_string.go"; DO NOT EDIT.
// Code generated by "stringer -type TokenType -output token_type_string.go token_type.go"; DO NOT EDIT.
package hclsyntax
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// An "invalid array index" compiler error signifies that the constant values (55) have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[TokenOBrace-123]
@ -35,6 +35,7 @@ func _() {
_ = x[TokenBang-33]
_ = x[TokenDot-46]
_ = x[TokenComma-44]
_ = x[TokenDoubleColon-11820]
_ = x[TokenEllipsis-8230]
_ = x[TokenFatArrow-8658]
_ = x[TokenQuestion-63]
@ -64,7 +65,7 @@ func _() {
_ = x[TokenNil-0]
}
const _TokenType_name = "TokenNilTokenNewlineTokenBangTokenPercentTokenBitwiseAndTokenApostropheTokenOParenTokenCParenTokenStarTokenPlusTokenCommaTokenMinusTokenDotTokenSlashTokenColonTokenSemicolonTokenLessThanTokenEqualTokenGreaterThanTokenQuestionTokenCommentTokenOHeredocTokenIdentTokenNumberLitTokenQuotedLitTokenStringLitTokenOBrackTokenCBrackTokenBitwiseXorTokenBacktickTokenCHeredocTokenOBraceTokenBitwiseOrTokenCBraceTokenBitwiseNotTokenOQuoteTokenCQuoteTokenTemplateControlTokenEllipsisTokenFatArrowTokenTemplateSeqEndTokenAndTokenOrTokenTemplateInterpTokenEqualOpTokenNotEqualTokenLessThanEqTokenGreaterThanEqTokenEOFTokenTabsTokenQuotedNewlineTokenStarStarTokenInvalidTokenBadUTF8"
const _TokenType_name = "TokenNilTokenNewlineTokenBangTokenPercentTokenBitwiseAndTokenApostropheTokenOParenTokenCParenTokenStarTokenPlusTokenCommaTokenMinusTokenDotTokenSlashTokenColonTokenSemicolonTokenLessThanTokenEqualTokenGreaterThanTokenQuestionTokenCommentTokenOHeredocTokenIdentTokenNumberLitTokenQuotedLitTokenStringLitTokenOBrackTokenCBrackTokenBitwiseXorTokenBacktickTokenCHeredocTokenOBraceTokenBitwiseOrTokenCBraceTokenBitwiseNotTokenOQuoteTokenCQuoteTokenTemplateControlTokenEllipsisTokenFatArrowTokenTemplateSeqEndTokenAndTokenOrTokenTemplateInterpTokenEqualOpTokenNotEqualTokenLessThanEqTokenGreaterThanEqTokenEOFTokenTabsTokenQuotedNewlineTokenStarStarTokenDoubleColonTokenInvalidTokenBadUTF8"
var _TokenType_map = map[TokenType]string{
0: _TokenType_name[0:8],
@ -119,8 +120,9 @@ var _TokenType_map = map[TokenType]string{
9225: _TokenType_name[603:612],
9252: _TokenType_name[612:630],
10138: _TokenType_name[630:643],
65533: _TokenType_name[643:655],
128169: _TokenType_name[655:667],
11820: _TokenType_name[643:659],
65533: _TokenType_name[659:671],
128169: _TokenType_name[671:683],
}
func (i TokenType) String() string {

View File

@ -234,6 +234,11 @@ func spaceAfterToken(subject, before, after *Token) bool {
// Don't split a function name from open paren in a call
return false
case (subject.Type == hclsyntax.TokenIdent && after.Type == hclsyntax.TokenDoubleColon) ||
(subject.Type == hclsyntax.TokenDoubleColon && after.Type == hclsyntax.TokenIdent):
// Don't split namespace segments in a function call
return false
case subject.Type == hclsyntax.TokenDot || after.Type == hclsyntax.TokenDot:
// Don't use spaces around attribute access dots
return false
@ -450,11 +455,11 @@ func tokenBracketChange(tok *Token) int {
// formatLine represents a single line of source code for formatting purposes,
// splitting its tokens into up to three "cells":
//
// lead: always present, representing everything up to one of the others
// assign: if line contains an attribute assignment, represents the tokens
// starting at (and including) the equals symbol
// comment: if line contains any non-comment tokens and ends with a
// single-line comment token, represents the comment.
// - lead: always present, representing everything up to one of the others
// - assign: if line contains an attribute assignment, represents the tokens
// starting at (and including) the equals symbol
// - comment: if line contains any non-comment tokens and ends with a
// single-line comment token, represents the comment.
//
// When formatting, the leading spaces of the first tokens in each of these
// cells is adjusted to align vertically their occurences on consecutive

View File

@ -10,7 +10,7 @@ import (
"github.com/hashicorp/hcl/v2"
)
//go:generate stringer -type tokenType scanner.go
//go:generate go run golang.org/x/tools/cmd/stringer -type tokenType scanner.go
type tokenType rune
const (

View File

@ -4,6 +4,24 @@ package json
import "strconv"
func _() {
// An "invalid array index" compiler error signifies that the constant values have changed.
// Re-run the stringer command to generate them again.
var x [1]struct{}
_ = x[tokenBraceO-123]
_ = x[tokenBraceC-125]
_ = x[tokenBrackO-91]
_ = x[tokenBrackC-93]
_ = x[tokenComma-44]
_ = x[tokenColon-58]
_ = x[tokenKeyword-75]
_ = x[tokenString-83]
_ = x[tokenNumber-78]
_ = x[tokenEOF-9220]
_ = x[tokenInvalid-0]
_ = x[tokenEquals-61]
}
const _tokenType_name = "tokenInvalidtokenCommatokenColontokenEqualstokenKeywordtokenNumbertokenStringtokenBrackOtokenBrackCtokenBraceOtokenBraceCtokenEOF"
var _tokenType_map = map[tokenType]string{

11
vendor/github.com/hashicorp/hcl/v2/tools.go generated vendored Normal file
View File

@ -0,0 +1,11 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
//go:build tools
// +build tools
package hcl
import (
_ "golang.org/x/tools/cmd/stringer"
)

View File

@ -40,6 +40,11 @@ func dynamicPassthrough(in cty.Value, path cty.Path) (cty.Value, error) {
// perspective, and will panic if it finds that they are not. For example if
// in is an object and out is a map, this function will still attempt to iterate
// through both as if they were the same.
// While the outermost in and out types may be compatible from a Convert
// perspective, inner types may not match when converting between maps and
// objects with optional attributes when the optional attributes don't match
// the map element type. Therefor in the case of a non-primitive type mismatch,
// we have to assume conversion was possible and pass the out type through.
func dynamicReplace(in, out cty.Type) cty.Type {
if in == cty.DynamicPseudoType || in == cty.NilType {
// Short circuit this case, there's no point worrying about this if in
@ -56,11 +61,9 @@ func dynamicReplace(in, out cty.Type) cty.Type {
// return it unchanged.
return out
case out.IsMapType():
var elemType cty.Type
// Maps are compatible with other maps or objects.
if in.IsMapType() {
elemType = dynamicReplace(in.ElementType(), out.ElementType())
return cty.Map(dynamicReplace(in.ElementType(), out.ElementType()))
}
if in.IsObjectType() {
@ -69,10 +72,10 @@ func dynamicReplace(in, out cty.Type) cty.Type {
types = append(types, t)
}
unifiedType, _ := unify(types, true)
elemType = dynamicReplace(unifiedType, out.ElementType())
return cty.Map(dynamicReplace(unifiedType, out.ElementType()))
}
return cty.Map(elemType)
return out
case out.IsObjectType():
// Objects are compatible with other objects and maps.
outTypes := map[string]cty.Type{}
@ -97,33 +100,29 @@ func dynamicReplace(in, out cty.Type) cty.Type {
return cty.Object(outTypes)
case out.IsSetType():
var elemType cty.Type
// Sets are compatible with other sets, lists, tuples.
if in.IsSetType() || in.IsListType() {
elemType = dynamicReplace(in.ElementType(), out.ElementType())
return cty.Set(dynamicReplace(in.ElementType(), out.ElementType()))
}
if in.IsTupleType() {
unifiedType, _ := unify(in.TupleElementTypes(), true)
elemType = dynamicReplace(unifiedType, out.ElementType())
return cty.Set(dynamicReplace(unifiedType, out.ElementType()))
}
return cty.Set(elemType)
return out
case out.IsListType():
var elemType cty.Type
// Lists are compatible with other lists, sets, and tuples.
if in.IsSetType() || in.IsListType() {
elemType = dynamicReplace(in.ElementType(), out.ElementType())
return cty.List(dynamicReplace(in.ElementType(), out.ElementType()))
}
if in.IsTupleType() {
unifiedType, _ := unify(in.TupleElementTypes(), true)
elemType = dynamicReplace(unifiedType, out.ElementType())
return cty.List(dynamicReplace(unifiedType, out.ElementType()))
}
return cty.List(elemType)
return out
case out.IsTupleType():
// Tuples are only compatible with other tuples
var types []cty.Type

View File

@ -1506,8 +1506,8 @@ func Keys(inputMap cty.Value) (cty.Value, error) {
}
// Lookup performs a dynamic lookup into a map.
// There are two required arguments, map and key, plus an optional default,
// which is a value to return if no key is found in map.
// There are three required arguments, inputMap and key, plus a defaultValue,
// which is a value to return if the given key is not found in the inputMap.
func Lookup(inputMap, key, defaultValue cty.Value) (cty.Value, error) {
return LookupFunc.Call([]cty.Value{inputMap, key, defaultValue})
}

View File

@ -30,8 +30,9 @@ func MakeToFunc(wantTy cty.Type) function.Function {
// messages to be more appropriate for an explicit type
// conversion, whereas the cty function system produces
// messages aimed at _implicit_ type conversions.
Type: cty.DynamicPseudoType,
AllowNull: true,
Type: cty.DynamicPseudoType,
AllowNull: true,
AllowDynamicType: true,
},
},
Type: func(args []cty.Value) (cty.Type, error) {

View File

@ -12,6 +12,9 @@ func marshal(val cty.Value, t cty.Type, path cty.Path, b *bytes.Buffer) error {
if val.IsMarked() {
return path.NewErrorf("value has marks, so it cannot be serialized as JSON")
}
if !val.IsKnown() {
return path.NewErrorf("value is not known")
}
// If we're going to decode as DynamicPseudoType then we need to save
// dynamic type information to recover the real type.
@ -24,10 +27,6 @@ func marshal(val cty.Value, t cty.Type, path cty.Path, b *bytes.Buffer) error {
return nil
}
if !val.IsKnown() {
return path.NewErrorf("value is not known")
}
// The caller should've guaranteed that the given val is conformant with
// the given type t, so we'll proceed under that assumption here.
@ -185,7 +184,10 @@ func marshalDynamic(val cty.Value, path cty.Path, b *bytes.Buffer) error {
return path.NewErrorf("failed to serialize type: %s", err)
}
b.WriteString(`{"value":`)
marshal(val, val.Type(), path, b)
err = marshal(val, val.Type(), path, b)
if err != nil {
return path.NewErrorf("failed to serialize value: %s", err)
}
b.WriteString(`,"type":`)
b.Write(typeJSON)
b.WriteRune('}')

View File

@ -1,6 +1,8 @@
package cty
import "math/big"
import (
"math/big"
)
// primitiveType is the hidden implementation of the various primitive types
// that are exposed as variables in this package.
@ -77,6 +79,18 @@ func rawNumberEqual(a, b *big.Float) bool {
case a.Sign() != b.Sign():
return false
default:
// First check if these are integers, and compare them directly. Floats
// need a more nuanced approach.
aInt, aAcc := a.Int(nil)
bInt, bAcc := b.Int(nil)
if aAcc != bAcc {
// only one is an exact integer value, so they can't be equal
return false
}
if aAcc == big.Exact {
return aInt.Cmp(bInt) == 0
}
// This format and precision matches that used by cty/json.Marshal,
// and thus achieves our definition of "two numbers are equal if
// we'd use the same JSON serialization for both of them".

4
vendor/modules.txt vendored
View File

@ -446,7 +446,7 @@ github.com/hashicorp/go-cty-funcs/cidr
github.com/hashicorp/go-cty-funcs/crypto
github.com/hashicorp/go-cty-funcs/encoding
github.com/hashicorp/go-cty-funcs/uuid
# github.com/hashicorp/hcl/v2 v2.19.1
# github.com/hashicorp/hcl/v2 v2.20.1
## explicit; go 1.18
github.com/hashicorp/hcl/v2
github.com/hashicorp/hcl/v2/ext/customdecode
@ -727,7 +727,7 @@ github.com/xeipuuv/gojsonreference
# github.com/xeipuuv/gojsonschema v1.2.0
## explicit
github.com/xeipuuv/gojsonschema
# github.com/zclconf/go-cty v1.14.1
# github.com/zclconf/go-cty v1.14.4
## explicit; go 1.18
github.com/zclconf/go-cty/cty
github.com/zclconf/go-cty/cty/convert