On Fri, Jun 3, 2016 at 10:06 PM, xdavidliu <[email protected]> wrote:
> with
>
>
> type foo
>     x::Int
>     foo(x) = x > 0 ? new(x) : new(-x)
> end
>
>
> type bar{T<:Integer}
>     x::T
> end
>
>
> type baz{T<:Integer}
>     x::T
>     baz(x) = x > 0 ? new(x) : new(-x)
> end
>
>
>
> "foo(-5).x" gives 5, "bar(-5).x" gives -5, but "baz(-5).x" gives a
> "MethodError: 'convert' has no method matching..." error.
>
> It seems the relevant section in the manual is this, but I only have a
> single field (as opposed to the examples in the link in which there are
> almost always two or more fields), so there should be no type disagreement
> or ambiguity here. Is this intended behavior?

Yes, this is.
This has nothing to do with ambiguity and is all about `bas{Int}` and
`baz` being completely different types (even though one is a
instantiation and subtype of the other) and has completely different
set of methods defined. The default constructor is always disabled
when custom inner constructors are defined.

Reply via email to