-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Open
Labels
compiler:loweringSyntax lowering (compiler front end, 2nd stage)Syntax lowering (compiler front end, 2nd stage)types and dispatchTypes, subtyping and method dispatchTypes, subtyping and method dispatch
Description
The constructor is missing:
julia> type A{T,S}
a::S
end
julia> A{Int}(5)
ERROR: MethodError: Cannot `convert` an object of type Int64 to an object of type A{Int64,S}
This may have arisen from a call to the constructor A{Int64,S}(...),
since type constructors fall back to convert methods.
in A{Int64,S}(::Int64) at ./sysimg.jl:63
in eval(::Module, ::Any) at ./boot.jl:234
in macro expansion at ./REPL.jl:92 [inlined]
in (::Base.REPL.##1#2{Base.REPL.REPLBackend})() at ./event.jl:46
When the tag-parameter is in the first position (or also multiple), I think it is unambiguous that I mean to call this constructor:
julia> (::Type{A{T}}){T,S}(a::S) = A{T,S}(a)
julia> A{Int16}(5)
A{Int16,Int64}(5)
Would it be possible to automatically provide it?
SimonDanisch, AzamatB, tpapp and hbsmith
Metadata
Metadata
Assignees
Labels
compiler:loweringSyntax lowering (compiler front end, 2nd stage)Syntax lowering (compiler front end, 2nd stage)types and dispatchTypes, subtyping and method dispatchTypes, subtyping and method dispatch