# Bug/unexpected behavior when extending Base.any with new type

**URL:** https://discourse.julialang.org/t/bug-unexpected-behavior-when-extending-base-any-with-new-type/94359
**Category:** General Usage
**Created:** [February 9, 2023, 4:41pm UTC](https://discourse.julialang.org/t/bug-unexpected-behavior-when-extending-base-any-with-new-type/94359 "2023-02-09T16:41:58Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [February 9, 2023, 4:51pm UTC](https://discourse.julialang.org/t/bug-unexpected-behavior-when-extending-base-any-with-new-type/94359/2 "2023-02-09T16:51:16Z")

</div>

This is because in your first case you are imputing a `Matrix{Int}`, which is not a `Matrix{Real}`, then another `any` method is being called. You have to change your function to accept `Matrix{<:Real}`, which are the matrices for which the elements are any subtypes of `Real`.

With `Matrix{Real}` you are asking the function to only accept the matrices that are specifically of type `Matrix{Real}`, which are matrices that accept, on its elements, any type of real number.

Search for the “covariance” of types in Julia, or for example: [Vector{Int} \<: Vector{Real} is false??? · JuliaNotes.jl](https://m3g.github.io/JuliaNotes.jl/stable/typevariance/), or [Why [1, 2, 3] is not a Vector{Number}?](https://discourse.julialang.org/t/why-1-2-3-is-not-a-vector-number/52645)

By the way, you can use:

```julia
julia> A = [0 0.0 0 1;
            0 0 0 0;
            0 0 0 1];

julia> any.(==(1), eachrow(A))
3-element BitVector:
 1
 0
 1

```

(ps: calling your function with the second type of matrix doesn’t work here either, because it is a `Matrix{Float64}` which is not either a subtype of `Matrix{Real}`. Your method works, as is, if you explicitly set `Real[0 0 1; 0 1 0 ; 0 0 1]`, such to get `Matrix{Real}`).

Finally, the error message (which is not great), is saying it is trying to test if a integer number is true or false, that is, using a integer where it expects a boolean. This occurs because the `any` function supports not providing the first argument (the function to be mapped to every element of the collection), and in that case it tests for true/false the array itself:

```julia
julia> any([true false])
true

julia> any(==(1),[1 0])
true

julia> any([1 0])
ERROR: TypeError: non-boolean (Int64) used in boolean context

```

---

_[View the full topic](https://discourse.julialang.org/t/bug-unexpected-behavior-when-extending-base-any-with-new-type/94359)._
