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:
joeduffy 2016-12-07 12:40:26 -08:00
parent 9e005fb6d8
commit eb6ef5a1b8

View file

@ -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.
func (p *binderValidatePhase) bindValue(node *ast.Node, val interface{}, ty *ast.Type) ast.Literal {
util.Assert(ty != nil)
var lit ast.Literal
if ty.IsDecors() {
return p.bindDecorsValue(node, val, ty.Decors)
lit = p.bindDecorsValue(node, val, ty.Decors)
} else if ty.IsPrimitive() {
return p.bindPrimitiveValue(node, val, *ty.Primitive)
lit = p.bindPrimitiveValue(node, val, *ty.Primitive)
} else if ty.IsStack() {
return p.bindServiceValue(node, val, ty)
lit = p.bindServiceValue(node, val, ty)
} else if ty.IsSchema() {
return p.bindSchemaValue(node, val, ty.Schema)
lit = p.bindSchemaValue(node, val, ty.Schema)
} else if ty.IsUnresolvedRef() {
util.FailM("Expected all unresolved refs to be gone by this phase in binding")
}
p.Diag().Errorf(errors.ErrorIncorrectType.At(node), ty, reflect.TypeOf(val))
return nil
if lit == nil {
// If no successful type binding happened, issue an error.
p.Diag().Errorf(errors.ErrorIncorrectType.At(node), ty, reflect.TypeOf(val))
}
return lit
}
func (p *binderValidatePhase) bindDecorsValue(node *ast.Node, val interface{}, decors *ast.TypeDecors) ast.Literal {