# Method call error: composite type

**URL:** <https://discourse.julialang.org/t/method-call-error-composite-type/54733>\
**Category:** New to Julia\
**Created:** [February 6, 2021, 2:36pm UTC](https://discourse.julialang.org/t/method-call-error-composite-type/54733 "2021-02-06T14:36:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)\
**Post date:** [February 6, 2021, 2:36pm UTC](https://discourse.julialang.org/t/method-call-error-composite-type/54733/1 "2021-02-06T14:36:59Z")

</div>

I have the following code,

```julia
abstract type A end
struct A1 <: A end
struct A2 <: A
    b1::Float64
    b2::Int64
end
function f(x, fonzi)
    if fonzi == A1() 
        return 2 * x
    elseif fonzi == A2() # <-
        return fonzi.b1^fonzi.b2 * x 
    else
        return 0.0
    end
end

```

and run

```julia
f(1, A1()) # 2
f(1, A2(2.0, 2)) # errors

```

How may `fonzi == A2()` be changed so that `f(1,A2(2.0, 2))` runs fine, instead of raising the following error:

```julia
ERROR: LoadError: MethodError: no method matching A2()
Closest candidates are:
  A2(::Float64, ::Int64) at /Users/Code/test.jl:4
  A2(::Any, ::Any) at /Users/Code/test.jl:4

```

Thanks in advance

---

<div class="post-metadata">

**Author:** ![hendri54](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/hendri54/32/9621_2.png) [@hendri54](https://discourse.julialang.org/u/hendri54)\
**Post date:** [February 7, 2021, 1:42pm UTC](https://discourse.julialang.org/t/method-call-error-composite-type/54733/2 "2021-02-07T13:42:37Z")

</div>

You are comparing values when you mean to compare types.

`fonzi == A2()` asks whether `fonzi` has the same value as `A2()`.

`fonzi isa A2` asks whether `fonzi` is of type `A2`. That’s what you want.

---

<div class="post-metadata">

**Author:** ![askvorts](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/askvorts/32/7120_2.png) [@askvorts](https://discourse.julialang.org/u/askvorts)\
**Post date:** [February 7, 2021, 4:08pm UTC](https://discourse.julialang.org/t/method-call-error-composite-type/54733/3 "2021-02-07T16:08:34Z")

</div>

Perfect! Thank you very much.
