Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor with type parameters behaves different from methods #10711

Closed
malbarbo opened this issue Apr 1, 2015 · 2 comments
Closed

Constructor with type parameters behaves different from methods #10711

malbarbo opened this issue Apr 1, 2015 · 2 comments
Labels
won't change Indicates that work won't continue on an issue or pull request

Comments

@malbarbo
Copy link

malbarbo commented Apr 1, 2015

julia> type Example{T}
           value::T
           Example(v::T) = new(v)
       end

julia> Example(20)
ERROR: `Example{T}` has no method matching Example{T}(::Int64)

julia> Example{T}(a::T) = Example{T}(a)
Example{T} (constructor with 1 method)

julia> Example(20)
Example{Int64}(20)

Maybe I'm missing something, but a I think the type parameter T in the constructor should be inferred as in the method.

@StefanKarpinski
Copy link
Member

When you define an inner constructor, no default constructors are given. The outer constructor one you defined is exactly the one that would be provided by default if no inner constructors were given. This is all documented in http://docs.julialang.org/en/release-0.3/manual/constructors/#inner-constructor-methods. If you find any of the documentation is unclear, please feel free to make documentation enhancements.

@StefanKarpinski StefanKarpinski added the won't change Indicates that work won't continue on an issue or pull request label Apr 1, 2015
@JeffBezanson
Copy link
Member

See for discussion about possible ways to reduce confusion here: #10146, #8135

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
won't change Indicates that work won't continue on an issue or pull request
Projects
None yet
Development

No branches or pull requests

3 participants