Skip to content

Commit cfa5148

Browse files
committed
typeassert return type of all methods of convert(Type{T}, T) where T
1 parent 0224bfc commit cfa5148

32 files changed

+57
-57
lines changed

base/Enums.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ abstract type Enum{T<:Integer} end
1717
basetype(::Type{<:Enum{T}}) where {T<:Integer} = T
1818

1919
(::Type{T})(x::Enum{T2}) where {T<:Integer,T2<:Integer} = T(bitcast(T2, x))::T
20-
Base.cconvert(::Type{T}, x::Enum{T2}) where {T<:Integer,T2<:Integer} = T(x)
20+
Base.cconvert(::Type{T}, x::Enum{T2}) where {T<:Integer,T2<:Integer} = T(x)::T
2121
Base.write(io::IO, x::Enum{T}) where {T<:Integer} = write(io, T(x))
2222
Base.read(io::IO, ::Type{T}) where {T<:Enum} = T(read(io, basetype(T)))
2323

base/abstractarray.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ See also: [`AbstractVector`](@ref), [`AbstractMatrix`](@ref), [`eltype`](@ref),
1414
AbstractArray
1515

1616
convert(::Type{T}, a::T) where {T<:AbstractArray} = a
17-
convert(::Type{AbstractArray{T}}, a::AbstractArray) where {T} = AbstractArray{T}(a)
18-
convert(::Type{AbstractArray{T,N}}, a::AbstractArray{<:Any,N}) where {T,N} = AbstractArray{T,N}(a)
17+
convert(::Type{AbstractArray{T}}, a::AbstractArray) where {T} = AbstractArray{T}(a)::AbstractArray{T}
18+
convert(::Type{AbstractArray{T,N}}, a::AbstractArray{<:Any,N}) where {T,N} = AbstractArray{T,N}(a)::AbstractArray{T,N}
1919

2020
"""
2121
size(A::AbstractArray, [dim])

base/abstractdict.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ push!(t::AbstractDict, p::Pair, q::Pair, r::Pair...) = push!(push!(push!(t, p),
565565
convert(::Type{T}, x::T) where {T<:AbstractDict} = x
566566

567567
function convert(::Type{T}, x::AbstractDict) where T<:AbstractDict
568-
h = T(x)
568+
h = T(x)::T
569569
if length(h) != length(x)
570570
error("key collision during dictionary conversion")
571571
end

base/array.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ oneunit(x::AbstractMatrix{T}) where {T} = _one(oneunit(T), x)
610610

611611
## Conversions ##
612612

613-
convert(::Type{T}, a::AbstractArray) where {T<:Array} = a isa T ? a : T(a)
613+
convert(::Type{T}, a::AbstractArray) where {T<:Array} = a isa T ? a : T(a)::T
614614

615615
promote_rule(a::Type{Array{T,n}}, b::Type{Array{S,n}}) where {T,n,S} = el_same(promote_type(T,S), a, b)
616616

base/baseext.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ VecElement
1616
# hook up VecElement constructor to Base.convert
1717
VecElement{T}(arg) where {T} = VecElement{T}(convert(T, arg))
1818
convert(::Type{T}, arg::T) where {T<:VecElement} = arg
19-
convert(::Type{T}, arg) where {T<:VecElement} = T(arg)
19+
convert(::Type{T}, arg) where {T<:VecElement} = T(arg)::T
2020

2121
# ## dims-type-converting Array constructors for convenience
2222
# type and dimensionality specified, accepting dims as series of Integers

base/bitarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -577,7 +577,7 @@ julia> BitArray(x+y == 3 for x = 1:2 for y = 1:3)
577577
BitArray(itr) = gen_bitarray(IteratorSize(itr), itr)
578578
BitArray{N}(itr) where N = gen_bitarrayN(BitArray{N}, IteratorSize(itr), itr)
579579

580-
convert(T::Type{<:BitArray}, a::AbstractArray) = a isa T ? a : T(a)
580+
convert(::Type{T}, a::AbstractArray) where {T<:BitArray} = a isa T ? a : T(a)::T
581581

582582
# generic constructor from an iterable without compile-time info
583583
# (we pass start(itr) explicitly to avoid a type-instability with filters)

base/broadcast.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function broadcasted(::OrOr, a, bc::Broadcasted)
195195
end
196196

197197
Base.convert(::Type{Broadcasted{NewStyle}}, bc::Broadcasted{Style,Axes,F,Args}) where {NewStyle,Style,Axes,F,Args} =
198-
Broadcasted{NewStyle,Axes,F,Args}(bc.f, bc.args, bc.axes)
198+
Broadcasted{NewStyle,Axes,F,Args}(bc.f, bc.args, bc.axes)::Broadcasted{NewStyle,Axes,F,Args}
199199

200200
function Base.show(io::IO, bc::Broadcasted{Style}) where {Style}
201201
print(io, Broadcasted)

base/char.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ end
181181
end
182182

183183
convert(::Type{AbstractChar}, x::Number) = Char(x) # default to Char
184-
convert(::Type{T}, x::Number) where {T<:AbstractChar} = T(x)
185-
convert(::Type{T}, x::AbstractChar) where {T<:Number} = T(x)
186-
convert(::Type{T}, c::AbstractChar) where {T<:AbstractChar} = T(c)
184+
convert(::Type{T}, x::Number) where {T<:AbstractChar} = T(x)::T
185+
convert(::Type{T}, x::AbstractChar) where {T<:Number} = T(x)::T
186+
convert(::Type{T}, c::AbstractChar) where {T<:AbstractChar} = T(c)::T
187187
convert(::Type{T}, c::T) where {T<:AbstractChar} = c
188188

189189
rem(x::AbstractChar, ::Type{T}) where {T<:Number} = rem(codepoint(x), T)

base/indices.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ struct LinearIndices{N,R<:NTuple{N,AbstractUnitRange{Int}}} <: AbstractArray{Int
476476
indices::R
477477
end
478478
convert(::Type{LinearIndices{N,R}}, inds::LinearIndices{N}) where {N,R<:NTuple{N,AbstractUnitRange{Int}}} =
479-
LinearIndices{N,R}(convert(R, inds.indices))
479+
LinearIndices{N,R}(convert(R, inds.indices))::LinearIndices{N,R}
480480

481481
LinearIndices(::Tuple{}) = LinearIndices{0,typeof(())}(())
482482
LinearIndices(inds::NTuple{N,AbstractUnitRange{<:Integer}}) where {N} =

base/multidimensional.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ module IteratorsMD
325325
convert(Tuple{Vararg{UnitRange{Int}}}, R)
326326

327327
convert(::Type{CartesianIndices{N,R}}, inds::CartesianIndices{N}) where {N,R} =
328-
CartesianIndices(convert(R, inds.indices))
328+
CartesianIndices(convert(R, inds.indices))::CartesianIndices{N,R}
329329

330330
# equality
331331
Base.:(==)(a::CartesianIndices{N}, b::CartesianIndices{N}) where N =

0 commit comments

Comments
 (0)