You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#4026 changed the default inner constructor to make calls to convert, a la:
type A
x::Int64#implicit inner constructor#A(x) = new(convert(Int64,x))end
The problem I see with this is that it's too easy to "lose" your only inner constructor for your type.
In [2]: type A
a::Int64end
In [3]:A(1)
Out [3]:A(1)
In [4]:A(x) =A(do_my_own_fallback_conversion(x))
Out [4]: A (constructor with 1 method)
In [5]:A(1.0)
Out [5]: ERROR: stack overflow
while loading In[5], in expression starting on line 1
Luckily, it seems like there's a fairly easy way to make this more intuitive:
type A
x::Int64#implicit inner constructors#A(x::Int64) = new(x)#A(x) = new(convert(Int64,x))end
Then when a user thinks to define her own fallback constructor, things don't break!
#4026 changed the default inner constructor to make calls to convert, a la:
The problem I see with this is that it's too easy to "lose" your only inner constructor for your type.
Luckily, it seems like there's a fairly easy way to make this more intuitive:
Then when a user thinks to define her own fallback constructor, things don't break!
Reference: https://groups.google.com/forum/#!searchin/julia-dev/gotcha/julia-dev/7WU_HimIsJc/5mj-ns-WN_gJ
The text was updated successfully, but these errors were encountered: