Typo in constructor, why does Julia not complain?

I assume that it ends up as dead code. Notice that you can do things like

julia> struct Foo
           x::Int
           y::Int
           Foo(x) = new(bar(x), bar(x + 1))
           bar(x) = x^2
       end

julia> Foo(3)
Foo(9, 16)

so it can’t be an error to define other functions than the constructor itself.

4 Likes