Пример #1
0
func assignable(t, u types.Type) bool {
	if t == nil || u == nil {
		return false
	}
	if t, ok := t.(*types.Basic); ok && t.Info&types.IsUntyped != 0 {
		// TODO: consider representability of const values
		switch u := underlying(u).(type) {
		case *types.Interface:
			return u.Empty()
		case *types.Basic:
			int := t.Info&types.IsInteger != 0
			float := t.Info&types.IsFloat != 0
			complex := t.Info&types.IsComplex != 0
			switch {
			case u.Info&types.IsBoolean != 0:
				return t.Info&types.IsBoolean != 0
			case u.Info&types.IsInteger != 0:
				return int
			case u.Info&types.IsFloat != 0:
				return int || float
			case u.Info&types.IsComplex != 0:
				return int || float || complex
			case u.Info&types.IsString != 0:
				return t.Info&types.IsString != 0
			}
		}
		return false
	}
	return types.IsAssignableTo(t, u)
}