Skip to content

Commit

Permalink
decoder: Implement InferType() for Any
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Apr 3, 2023
1 parent ef1948e commit c5bba37
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions decoder/expr_any.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,27 @@ package decoder
import (
"github.com/hashicorp/hcl-lang/schema"
"github.com/hashicorp/hcl/v2"
"github.com/zclconf/go-cty/cty"
)

type Any struct {
expr hcl.Expression
cons schema.AnyExpression
pathCtx *PathContext
}

func (a Any) InferType() (cty.Type, bool) {
consType, ok := a.cons.ConstraintType()
if !ok {
return consType, false
}

if consType == cty.DynamicPseudoType && !isEmptyExpression(a.expr) {
val, diags := a.expr.Value(nil)
if !diags.HasErrors() {
consType = val.Type()
}
}

return consType, true
}

0 comments on commit c5bba37

Please sign in to comment.