# Constructor compilation error

**URL:** <https://discourse.julialang.org/t/constructor-compilation-error/55662>\
**Category:** General Usage\
**Created:** [February 20, 2021, 3:52am UTC](https://discourse.julialang.org/t/constructor-compilation-error/55662 "2021-02-20T03:52:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gideonsimpson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gideonsimpson/32/1928_2.png) [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)\
**Post date:** [February 20, 2021, 3:52am UTC](https://discourse.julialang.org/t/constructor-compilation-error/55662/1 "2021-02-20T03:52:35Z")

</div>

I have this very naive custom data structure and an associated constructor:

```julia
module MyModule

struct MyStruct{TG,TF<:AbstractFloat}
    g::TG
    Δt::TF
end

function MyStruct(g::TG, Δt::TF) where {TG, TF<:AbstractFloat}
    return MyStruct(g, Δt)
end

end

```

and when I try to use it:

```julia
using MyModule

```

I get the following errors:

```julia
WARNING: Method definition (::Type{MyModule.MyStruct{TG, TF} where TF<:AbstractFloat where TG})(TG, TF<:AbstractFloat) where {TG, TF<:AbstractFloat} in module MyModule at /Users/grs53/code/scratch/MyModule.jl:4 overwritten at /Users/grs53/code/scratch/MyModule.jl:8.
  **incremental compilation may be fatally broken for this module**

```

I know this constructor does essentially nothing – is that the source of the problem? How should I handle such a case?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [February 20, 2021, 8:48am UTC](https://discourse.julialang.org/t/constructor-compilation-error/55662/2 "2021-02-20T08:48:54Z")

</div>

I’m not 100% on this but it looks to me like your outer constructor is exactly the same as the default constructor which is created when you define the struct. I guess rather than asking how to handle this I would ask why are you doing it?

---

<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 20, 2021, 11:15am UTC](https://discourse.julialang.org/t/constructor-compilation-error/55662/3 "2021-02-20T11:15:36Z")

</div>

As pointed above, the function is overwriting the default constructor. But note also that it becomes self-referential and a call to it may well end in a stack overflow.

(If you need a constructor with the same parameters as the default constructor you need to define an inner constructor, take a look at the manual section below)

[https://docs.julialang.org/en/v1/manual/constructors/#man-inner-constructor-methods](https://docs.julialang.org/en/v1/manual/constructors/#man-inner-constructor-methods)

---

<div class="post-metadata">

**Author:** ![gideonsimpson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gideonsimpson/32/1928_2.png) [@gideonsimpson](https://discourse.julialang.org/u/gideonsimpson)\
**Post date:** [February 20, 2021, 6:26pm UTC](https://discourse.julialang.org/t/constructor-compilation-error/55662/4 "2021-02-20T18:26:22Z")

</div>

Because I thought I needed a separate constructor even in this trivial case 😑
