Skip to content

Commit

Permalink
decoder: reflect Constraint when collecting AsTypeOf targets (#209)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko authored Feb 20, 2023
1 parent 5a59121 commit 1ed299c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
17 changes: 13 additions & 4 deletions decoder/reference_targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -499,12 +499,21 @@ func asTypeOfAttrExpr(attrs hcl.Attributes, bSchema *schema.BlockSchema) (cty.Ty
return cty.DynamicPseudoType, false
}

ec := ExprConstraints(bSchema.Body.Attributes[attrName].Expr)
_, ok = ec.TypeDeclarationExpr()
if !ok {
return cty.DynamicPseudoType, false
aSchema := bSchema.Body.Attributes[attrName]
if aSchema.Constraint != nil {
_, ok := aSchema.Constraint.(schema.TypeDeclaration)
if !ok {
return cty.DynamicPseudoType, false
}
} else {
ec := ExprConstraints(aSchema.Expr)
_, ok = ec.TypeDeclarationExpr()
if !ok {
return cty.DynamicPseudoType, false
}
}

// TODO: TypeConstraintWithDefaults
typeDecl, diags := typeexpr.TypeConstraint(attr.Expr)
if diags.HasErrors() {
return cty.DynamicPseudoType, false
Expand Down
4 changes: 3 additions & 1 deletion schema/constraint_type_declaration.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package schema
// TypeDeclaration represents a type declaration as
// interpreted by HCL's ext/typeexpr package,
// i.e. declaration of cty.Type in HCL
type TypeDeclaration struct{}
type TypeDeclaration struct {
// TODO: optional object attribute mode
}

func (TypeDeclaration) isConstraintImpl() constraintSigil {
return constraintSigil{}
Expand Down

0 comments on commit 1ed299c

Please sign in to comment.