Fix control paths within bindValue
Any of the bindXValue routines can fail if there was no way to convert the interface{} to an ast.Literal. In such a case, we need to issue an error about the wrong type being passed. Unfortunately, in the most recent set of changes, we began simply returning nils without issuing the error. This change fixes that.
This commit is contained in:
parent
9e005fb6d8
commit
eb6ef5a1b8
|
@ -616,20 +616,24 @@ func (p *binderValidatePhase) bindProperties(node *ast.Node, props ast.Propertie
|
||||||
// bindValue takes a value and binds it to a type and literal AST node, returning nils if the conversions fails.
|
// bindValue takes a value and binds it to a type and literal AST node, returning nils if the conversions fails.
|
||||||
func (p *binderValidatePhase) bindValue(node *ast.Node, val interface{}, ty *ast.Type) ast.Literal {
|
func (p *binderValidatePhase) bindValue(node *ast.Node, val interface{}, ty *ast.Type) ast.Literal {
|
||||||
util.Assert(ty != nil)
|
util.Assert(ty != nil)
|
||||||
|
var lit ast.Literal
|
||||||
if ty.IsDecors() {
|
if ty.IsDecors() {
|
||||||
return p.bindDecorsValue(node, val, ty.Decors)
|
lit = p.bindDecorsValue(node, val, ty.Decors)
|
||||||
} else if ty.IsPrimitive() {
|
} else if ty.IsPrimitive() {
|
||||||
return p.bindPrimitiveValue(node, val, *ty.Primitive)
|
lit = p.bindPrimitiveValue(node, val, *ty.Primitive)
|
||||||
} else if ty.IsStack() {
|
} else if ty.IsStack() {
|
||||||
return p.bindServiceValue(node, val, ty)
|
lit = p.bindServiceValue(node, val, ty)
|
||||||
} else if ty.IsSchema() {
|
} else if ty.IsSchema() {
|
||||||
return p.bindSchemaValue(node, val, ty.Schema)
|
lit = p.bindSchemaValue(node, val, ty.Schema)
|
||||||
} else if ty.IsUnresolvedRef() {
|
} else if ty.IsUnresolvedRef() {
|
||||||
util.FailM("Expected all unresolved refs to be gone by this phase in binding")
|
util.FailM("Expected all unresolved refs to be gone by this phase in binding")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if lit == nil {
|
||||||
|
// If no successful type binding happened, issue an error.
|
||||||
p.Diag().Errorf(errors.ErrorIncorrectType.At(node), ty, reflect.TypeOf(val))
|
p.Diag().Errorf(errors.ErrorIncorrectType.At(node), ty, reflect.TypeOf(val))
|
||||||
return nil
|
}
|
||||||
|
return lit
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *binderValidatePhase) bindDecorsValue(node *ast.Node, val interface{}, decors *ast.TypeDecors) ast.Literal {
|
func (p *binderValidatePhase) bindDecorsValue(node *ast.Node, val interface{}, decors *ast.TypeDecors) ast.Literal {
|
||||||
|
|
Loading…
Reference in a new issue