# No Method matching: Constructors

**URL:** <https://discourse.julialang.org/t/no-method-matching-constructors/31841>\
**Category:** New to Julia\
**Created:** [December 4, 2019, 10:06am UTC](https://discourse.julialang.org/t/no-method-matching-constructors/31841 "2019-12-04T10:06:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![patdax](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@patdax](https://discourse.julialang.org/u/patdax)\
**Post date:** [December 4, 2019, 10:06am UTC](https://discourse.julialang.org/t/no-method-matching-constructors/31841/1 "2019-12-04T10:06:37Z")

</div>

I am having difficulties defining a module and testing it.  
I have the following architecture:

file: my\_struct.jl

```julia
mutable struct my_struct
    x
    y
    z
end

function my_struct(x, y)
   z = Vector(undef, x)
   return my_struct(x,y,z)
end

```

file my\_module.jl

```julia
module my_module

export my_struct

include("my_struct.jl")

end

```

file test.jl

```julia
include("my_module.jl")
using .my_module

b = my_struct(x,y)

```

When running test.jl I get an error saying “No method matching my\_struct(::type, ::type). Closest candidates are my\_struct(::Any, ::Any, ::Any)”.  
Can anybody explain why I can not use the self-built constructor in test.jl and how to fix this?

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [December 4, 2019, 10:13am UTC](https://discourse.julialang.org/t/no-method-matching-constructors/31841/2 "2019-12-04T10:13:58Z")

</div>

It works when I test it in my REPL…

```nohighlight

julia> mutable struct my_struct
           x
           y
           z
       end

julia> my_struct(x,y) = my_struct(x,y,Vector(undef,x))
my_struct

julia> my_struct(1,2)
my_struct(1, 2, Any[#undef])

```

---

<div class="post-metadata">

**Author:** ![patdax](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@patdax](https://discourse.julialang.org/u/patdax)\
**Post date:** [December 4, 2019, 10:25am UTC](https://discourse.julialang.org/t/no-method-matching-constructors/31841/3 "2019-12-04T10:25:21Z")

</div>

You are right it works it the simplified example.  
Could you explain how I can avoid the warnings:  
“replacing module by my\_module.”  
“using my\_module.my\_struct in module Main conflicts with an existing identifier.”

---

<div class="post-metadata">

**Author:** ![chakravala](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/chakravala/32/6832_2.png) [@chakravala](https://discourse.julialang.org/u/chakravala)\
**Post date:** [December 4, 2019, 10:43am UTC](https://discourse.julialang.org/t/no-method-matching-constructors/31841/4 "2019-12-04T10:43:54Z")

</div>

Restarting the REPL would certainly fix that.

---

<div class="post-metadata">

**Author:** ![patdax](https://avatars.discourse-cdn.com/v4/letter/p/57b2e6/32.png) [@patdax](https://discourse.julialang.org/u/patdax)\
**Post date:** [December 4, 2019, 10:45am UTC](https://discourse.julialang.org/t/no-method-matching-constructors/31841/5 "2019-12-04T10:45:23Z")

</div>

Thank you!
