@@ -396,21 +396,14 @@ oneunit(x::AbstractMatrix{T}) where {T} = _one(oneunit(T), x)
396396# arises in similar(dest, Pair{Union{},Union{}}) where dest::Dict:
397397convert (:: Type{Vector{Union{}}} , a:: Vector{Union{}} ) = a
398398
399- convert (:: Type{Vector} , x:: AbstractVector{T} ) where {T} = convert (Vector{T}, x)
400- convert (:: Type{Matrix} , x:: AbstractMatrix{T} ) where {T} = convert (Matrix{T}, x)
401-
402- convert (:: Type{Array{T}} , x:: Array{T,n} ) where {T,n} = x
403- convert (:: Type{Array{T,n}} , x:: Array{T,n} ) where {T,n} = x
404-
405- convert (:: Type{Array{T}} , x:: AbstractArray{S,n} ) where {T,n,S} = convert (Array{T,n}, x)
406- convert (:: Type{Array{T,n}} , x:: AbstractArray{S,n} ) where {T,n,S} = copy! (Array {T,n} (uninitialized, size (x)), x)
407-
408399promote_rule (a:: Type{Array{T,n}} , b:: Type{Array{S,n}} ) where {T,n,S} = el_same (promote_type (T,S), a, b)
409400
410- # constructors should make copies
401+ # # Constructors ##
411402
412403if module_name (@__MODULE__ ) === :Base # avoid method overwrite
413- (:: Type{T} )(x:: T ) where {T<: Array } = copy (x)
404+ # constructors should make copies
405+ Array {T,N} (x:: AbstractArray{S,N} ) where {T,N,S} = copy! (Array {T,N} (uninitialized, size (x)), x)
406+ AbstractArray {T,N} (A:: AbstractArray{S,N} ) where {T,N,S} = copy! (similar (A,T), A)
414407end
415408
416409# # copying iterators to containers
@@ -498,14 +491,26 @@ end
498491# gets a chance to see it, so that recursive calls to the caller
499492# don't trigger the inference limiter
500493if isdefined (Core, :Inference )
501- macro default_eltype (itrt)
494+ macro default_eltype (itr)
495+ I = esc (itr)
502496 return quote
503- Core. Inference. return_type (first, Tuple{$ (esc (itrt))})
497+ if $ I isa Generator && ($ I). f isa Type
498+ ($ I). f
499+ else
500+ Core. Inference. return_type (first, Tuple{typeof ($ I)})
501+ end
504502 end
505503 end
506504else
507- macro default_eltype (itrt)
508- return :(Any)
505+ macro default_eltype (itr)
506+ I = esc (itr)
507+ return quote
508+ if $ I isa Generator && ($ I). f isa Type
509+ ($ I). f
510+ else
511+ Any
512+ end
513+ end
509514 end
510515end
511516
@@ -514,7 +519,7 @@ _array_for(::Type{T}, itr, ::HasShape) where {T} = similar(Array{T}, indices(itr
514519
515520function collect (itr:: Generator )
516521 isz = iteratorsize (itr. iter)
517- et = @default_eltype (typeof ( itr) )
522+ et = @default_eltype (itr)
518523 if isa (isz, SizeUnknown)
519524 return grow_to! (Vector {et} (), itr)
520525 else
@@ -528,12 +533,12 @@ function collect(itr::Generator)
528533end
529534
530535_collect (c, itr, :: EltypeUnknown , isz:: SizeUnknown ) =
531- grow_to! (_similar_for (c, @default_eltype (typeof ( itr) ), itr, isz), itr)
536+ grow_to! (_similar_for (c, @default_eltype (itr), itr, isz), itr)
532537
533538function _collect (c, itr, :: EltypeUnknown , isz:: Union{HasLength,HasShape} )
534539 st = start (itr)
535540 if done (itr,st)
536- return _similar_for (c, @default_eltype (typeof ( itr) ), itr, isz)
541+ return _similar_for (c, @default_eltype (itr), itr, isz)
537542 end
538543 v1, st = next (itr, st)
539544 collect_to_with_first! (_similar_for (c, typeof (v1), itr, isz), v1, itr, st)
0 commit comments