bind/utils: helper to check wether a func is 'func String() string'

This commit is contained in:
Sebastien Binet 2015-07-28 14:35:59 +02:00
parent 0058490f51
commit a083052bf6
1 changed files with 32 additions and 0 deletions

View File

@ -11,3 +11,35 @@ import (
func isErrorType(typ types.Type) bool {
return typ == types.Universe.Lookup("error").Type()
}
func isStringer(obj types.Object) bool {
switch obj := obj.(type) {
case *types.Func:
if obj.Name() != "String" {
return false
}
sig, ok := obj.Type().(*types.Signature)
if !ok {
return false
}
if sig.Recv() == nil {
return false
}
if sig.Params().Len() != 0 {
return false
}
res := sig.Results()
if res.Len() != 1 {
return false
}
ret := res.At(0).Type()
if ret != types.Universe.Lookup("string").Type() {
return false
}
return true
default:
return false
}
return false
}