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 =

base/namedtuple.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ convert(::Type{NamedTuple{names,T}}, nt::NamedTuple{names,T}) where {names,T<:Tu
148148
convert(::Type{NamedTuple{names}}, nt::NamedTuple{names}) where {names} = nt
149149

150150
function convert(::Type{NamedTuple{names,T}}, nt::NamedTuple{names}) where {names,T<:Tuple}
151-
NamedTuple{names,T}(T(nt))
151+
NamedTuple{names,T}(T(nt))::NamedTuple{names,T}
152152
end
153153

154154
if nameof(@__MODULE__) === :Base

base/pair.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ last(p::Pair) = p.second
5555

5656
convert(::Type{Pair{A,B}}, x::Pair{A,B}) where {A,B} = x
5757
function convert(::Type{Pair{A,B}}, x::Pair) where {A,B}
58-
Pair{A,B}(convert(A, x[1]), convert(B, x[2]))
58+
Pair{A,B}(convert(A, x[1]), convert(B, x[2]))::Pair{A,B}
5959
end
6060

6161
promote_rule(::Type{Pair{A1,B1}}, ::Type{Pair{A2,B2}}) where {A1,B1,A2,B2} =

base/pointer.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@ const C_NULL = bitcast(Ptr{Cvoid}, 0)
2020
# TODO: deprecate these conversions. C doesn't even allow them.
2121

2222
# pointer to integer
23-
convert(::Type{T}, x::Ptr) where {T<:Integer} = T(UInt(x))
23+
convert(::Type{T}, x::Ptr) where {T<:Integer} = T(UInt(x))::T
2424

2525
# integer to pointer
2626
convert(::Type{Ptr{T}}, x::Union{Int,UInt}) where {T} = Ptr{T}(x)
2727

2828
# pointer to pointer
2929
convert(::Type{Ptr{T}}, p::Ptr{T}) where {T} = p
30-
convert(::Type{Ptr{T}}, p::Ptr) where {T} = bitcast(Ptr{T}, p)
30+
convert(::Type{Ptr{T}}, p::Ptr) where {T} = bitcast(Ptr{T}, p)::Ptr{T}
3131

3232
# object to pointer (when used with ccall)
3333

base/range.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ abstract type AbstractRange{T} <: AbstractArray{T,1} end
252252
RangeStepStyle(::Type{<:AbstractRange}) = RangeStepIrregular()
253253
RangeStepStyle(::Type{<:AbstractRange{<:Integer}}) = RangeStepRegular()
254254

255-
convert(::Type{T}, r::AbstractRange) where {T<:AbstractRange} = r isa T ? r : T(r)
255+
convert(::Type{T}, r::AbstractRange) where {T<:AbstractRange} = r isa T ? r : T(r)::T
256256

257257
## ordinal ranges
258258

base/refpointer.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ IteratorSize(::Type{<:Ref}) = HasShape{0}()
101101
unsafe_convert(::Type{Ref{T}}, x::Ref{T}) where {T} = unsafe_convert(Ptr{T}, x)
102102
unsafe_convert(::Type{Ref{T}}, x) where {T} = unsafe_convert(Ptr{T}, x)
103103

104-
convert(::Type{Ref{T}}, x) where {T} = RefValue{T}(x)
104+
convert(::Type{Ref{T}}, x) where {T} = RefValue{T}(x)::RefValue{T}
105105

106106
### Methods for a Ref object that is backed by an array at index i
107107
struct RefArray{T,A<:AbstractArray{T},R} <: Ref{T}

base/set.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ function hash(s::AbstractSet, h::UInt)
548548
end
549549

550550
convert(::Type{T}, s::T) where {T<:AbstractSet} = s
551-
convert(::Type{T}, s::AbstractSet) where {T<:AbstractSet} = T(s)
551+
convert(::Type{T}, s::AbstractSet) where {T<:AbstractSet} = T(s)::T
552552

553553

554554
## replace/replace! ##

base/show.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ function IOContext(io::IO, dict::ImmutableDict)
303303
IOContext{typeof(io0)}(io0, dict)
304304
end
305305

306-
convert(::Type{IOContext}, io::IO) = IOContext(unwrapcontext(io)...)
306+
convert(::Type{IOContext}, io::IO) = IOContext(unwrapcontext(io)...)::IOContext
307307

308308
IOContext(io::IO) = convert(IOContext, io)
309309

base/some.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ end
3535
convert(::Type{T}, x::T) where {T>:Nothing} = x
3636
convert(::Type{T}, x) where {T>:Nothing} = convert(nonnothingtype_checked(T), x)
3737
convert(::Type{Some{T}}, x::Some{T}) where {T} = x
38-
convert(::Type{Some{T}}, x::Some) where {T} = Some{T}(convert(T, x.value))
38+
convert(::Type{Some{T}}, x::Some) where {T} = Some{T}(convert(T, x.value))::Some{T}
3939

4040
function show(io::IO, x::Some)
4141
if get(io, :typeinfo, Any) == typeof(x)

base/strings/basic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ Symbol(s::AbstractString) = Symbol(String(s))
229229
Symbol(x...) = Symbol(string(x...))
230230

231231
convert(::Type{T}, s::T) where {T<:AbstractString} = s
232-
convert(::Type{T}, s::AbstractString) where {T<:AbstractString} = T(s)
232+
convert(::Type{T}, s::AbstractString) where {T<:AbstractString} = T(s)::T
233233

234234
## summary ##
235235

base/strings/substring.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ SubString{T}(s::T) where {T<:AbstractString} = SubString{T}(s, 1, lastindex(s)::
5555
@propagate_inbounds maybeview(s::AbstractString, args...) = getindex(s, args...)
5656

5757
convert(::Type{SubString{S}}, s::AbstractString) where {S<:AbstractString} =
58-
SubString(convert(S, s))
58+
SubString(convert(S, s))::SubString{S}
5959
convert(::Type{T}, s::T) where {T<:SubString} = s
6060

6161
# Regex match allows only Union{String, SubString{String}} so define conversion to this type
6262
convert(::Type{Union{String, SubString{String}}}, s::String) = s
6363
convert(::Type{Union{String, SubString{String}}}, s::SubString{String}) = s
64-
convert(::Type{Union{String, SubString{String}}}, s::AbstractString) = convert(String, s)
64+
convert(::Type{Union{String, SubString{String}}}, s::AbstractString) = convert(String, s)::String
6565

6666
function String(s::SubString{String})
6767
parent = s.string

base/twiceprecision.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,10 +268,10 @@ TwicePrecision{T}(x::Number) where {T} = TwicePrecision{T}(T(x), zero(T))
268268

269269
convert(::Type{TwicePrecision{T}}, x::TwicePrecision{T}) where {T} = x
270270
convert(::Type{TwicePrecision{T}}, x::TwicePrecision) where {T} =
271-
TwicePrecision{T}(convert(T, x.hi), convert(T, x.lo))
271+
TwicePrecision{T}(convert(T, x.hi), convert(T, x.lo))::TwicePrecision{T}
272272

273-
convert(::Type{T}, x::TwicePrecision) where {T<:Number} = T(x)
274-
convert(::Type{TwicePrecision{T}}, x::Number) where {T} = TwicePrecision{T}(x)
273+
convert(::Type{T}, x::TwicePrecision) where {T<:Number} = T(x)::T
274+
convert(::Type{TwicePrecision{T}}, x::Number) where {T} = TwicePrecision{T}(x)::TwicePrecision{T}
275275

276276
float(x::TwicePrecision{<:AbstractFloat}) = x
277277
float(x::TwicePrecision) = TwicePrecision(float(x.hi), float(x.lo))

doc/src/manual/conversion-and-promotion.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ For example, this definition states that it's valid to `convert` any `Number` ty
181181
any other by calling a 1-argument constructor:
182182

183183
```julia
184-
convert(::Type{T}, x::Number) where {T<:Number} = T(x)
184+
convert(::Type{T}, x::Number) where {T<:Number} = T(x)::T
185185
```
186186

187187
This means that new `Number` types only need to define constructors, since this

stdlib/Dates/test/periods.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ Beat(p::Period) = Beat(Dates.toms(p) ÷ 86400)
283283
Dates.toms(b::Beat) = Dates.value(b) * 86400
284284
Dates._units(b::Beat) = " beat" * (abs(Dates.value(b)) == 1 ? "" : "s")
285285
Base.promote_rule(::Type{Dates.Day}, ::Type{Beat}) = Dates.Millisecond
286-
Base.convert(::Type{T}, b::Beat) where {T<:Dates.Millisecond} = T(Dates.toms(b))
286+
Base.convert(::Type{T}, b::Beat) where {T<:Dates.Millisecond} = T(Dates.toms(b))::T
287287

288288
@test Beat(1000) == Dates.Day(1)
289289
@test Beat(1) < Dates.Day(1)

stdlib/LinearAlgebra/src/adjtrans.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ IndexStyle(::Type{<:AdjOrTransAbsMat}) = IndexCartesian()
308308
@propagate_inbounds getindex(v::AdjOrTransAbsVec, ::Colon, ::Colon) = wrapperop(v)(v.parent[:])
309309

310310
# conversion of underlying storage
311-
convert(::Type{Adjoint{T,S}}, A::Adjoint) where {T,S} = Adjoint{T,S}(convert(S, A.parent))
312-
convert(::Type{Transpose{T,S}}, A::Transpose) where {T,S} = Transpose{T,S}(convert(S, A.parent))
311+
convert(::Type{Adjoint{T,S}}, A::Adjoint) where {T,S} = Adjoint{T,S}(convert(S, A.parent))::Adjoint{T,S}
312+
convert(::Type{Transpose{T,S}}, A::Transpose) where {T,S} = Transpose{T,S}(convert(S, A.parent))::Transpose{T,S}
313313

314314
# Strides and pointer for transposed strided arrays — but only if the elements are actually stored in memory
315315
Base.strides(A::Adjoint{<:Real, <:AbstractVector}) = (stride(A.parent, 2), stride(A.parent, 1))

stdlib/LinearAlgebra/src/bidiag.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ promote_rule(::Type{<:Tridiagonal}, ::Type{<:Bidiagonal}) = Tridiagonal
200200
# When asked to convert Bidiagonal to AbstractMatrix{T}, preserve structure by converting to Bidiagonal{T} <: AbstractMatrix{T}
201201
AbstractMatrix{T}(A::Bidiagonal) where {T} = convert(Bidiagonal{T}, A)
202202

203-
convert(T::Type{<:Bidiagonal}, m::AbstractMatrix) = m isa T ? m : T(m)
203+
convert(::Type{T}, m::AbstractMatrix) where {T<:Bidiagonal} = m isa T ? m : T(m)::T
204204

205205
similar(B::Bidiagonal, ::Type{T}) where {T} = Bidiagonal(similar(B.dv, T), similar(B.ev, T), B.uplo)
206206
similar(B::Bidiagonal, ::Type{T}, dims::Union{Dims{1},Dims{2}}) where {T} = zeros(T, dims...)

stdlib/LinearAlgebra/src/factorization.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ function det(F::Factorization)
5454
end
5555

5656
convert(::Type{T}, f::T) where {T<:Factorization} = f
57-
convert(::Type{T}, f::Factorization) where {T<:Factorization} = T(f)
57+
convert(::Type{T}, f::Factorization) where {T<:Factorization} = T(f)::T
5858

59-
convert(::Type{T}, f::Factorization) where {T<:AbstractArray} = T(f)
59+
convert(::Type{T}, f::Factorization) where {T<:AbstractArray} = T(f)::T
6060

6161
### General promotion rules
6262
Factorization{T}(F::Factorization{T}) where {T} = F

stdlib/LinearAlgebra/src/givens.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ struct Rotation{T} <: AbstractRotation{T}
4444
end
4545

4646
convert(::Type{T}, r::T) where {T<:AbstractRotation} = r
47-
convert(::Type{T}, r::AbstractRotation) where {T<:AbstractRotation} = T(r)
47+
convert(::Type{T}, r::AbstractRotation) where {T<:AbstractRotation} = T(r)::T
4848

4949
Givens(i1, i2, c, s) = Givens(i1, i2, promote(c, s)...)
5050
Givens{T}(G::Givens{T}) where {T} = G

stdlib/LinearAlgebra/src/special.jl

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,20 +62,20 @@ end
6262
const ConvertibleSpecialMatrix = Union{Diagonal,Bidiagonal,SymTridiagonal,Tridiagonal,AbstractTriangular}
6363
const PossibleTriangularMatrix = Union{Diagonal, Bidiagonal, AbstractTriangular}
6464

65-
convert(T::Type{<:Diagonal}, m::ConvertibleSpecialMatrix) = m isa T ? m :
66-
isdiag(m) ? T(m) : throw(ArgumentError("matrix cannot be represented as Diagonal"))
67-
convert(T::Type{<:SymTridiagonal}, m::ConvertibleSpecialMatrix) = m isa T ? m :
68-
issymmetric(m) && isbanded(m, -1, 1) ? T(m) : throw(ArgumentError("matrix cannot be represented as SymTridiagonal"))
69-
convert(T::Type{<:Tridiagonal}, m::ConvertibleSpecialMatrix) = m isa T ? m :
70-
isbanded(m, -1, 1) ? T(m) : throw(ArgumentError("matrix cannot be represented as Tridiagonal"))
71-
72-
convert(T::Type{<:LowerTriangular}, m::Union{LowerTriangular,UnitLowerTriangular}) = m isa T ? m : T(m)
73-
convert(T::Type{<:UpperTriangular}, m::Union{UpperTriangular,UnitUpperTriangular}) = m isa T ? m : T(m)
74-
75-
convert(T::Type{<:LowerTriangular}, m::PossibleTriangularMatrix) = m isa T ? m :
76-
istril(m) ? T(m) : throw(ArgumentError("matrix cannot be represented as LowerTriangular"))
77-
convert(T::Type{<:UpperTriangular}, m::PossibleTriangularMatrix) = m isa T ? m :
78-
istriu(m) ? T(m) : throw(ArgumentError("matrix cannot be represented as UpperTriangular"))
65+
convert(::Type{T}, m::ConvertibleSpecialMatrix) where {T<:Diagonal} = m isa T ? m :
66+
isdiag(m) ? T(m)::T : throw(ArgumentError("matrix cannot be represented as Diagonal"))
67+
convert(::Type{T}, m::ConvertibleSpecialMatrix) where {T<:SymTridiagonal} = m isa T ? m :
68+
issymmetric(m) && isbanded(m, -1, 1) ? T(m)::T : throw(ArgumentError("matrix cannot be represented as SymTridiagonal"))
69+
convert(::Type{T}, m::ConvertibleSpecialMatrix) where {T<:Tridiagonal} = m isa T ? m :
70+
isbanded(m, -1, 1) ? T(m)::T : throw(ArgumentError("matrix cannot be represented as Tridiagonal"))
71+
72+
convert(::Type{T}, m::Union{LowerTriangular,UnitLowerTriangular}) where {T<:LowerTriangular} = m isa T ? m : T(m)::T
73+
convert(::Type{T}, m::Union{UpperTriangular,UnitUpperTriangular}) where {T<:UpperTriangular} = m isa T ? m : T(m)::T
74+
75+
convert(::Type{T}, m::PossibleTriangularMatrix) where {T<:LowerTriangular} = m isa T ? m :
76+
istril(m) ? T(m)::T : throw(ArgumentError("matrix cannot be represented as LowerTriangular"))
77+
convert(::Type{T}, m::PossibleTriangularMatrix) where {T<:UpperTriangular} = m isa T ? m :
78+
istriu(m) ? T(m)::T : throw(ArgumentError("matrix cannot be represented as UpperTriangular"))
7979

8080
# Constructs two method definitions taking into account (assumed) commutativity
8181
# e.g. @commutative f(x::S, y::T) where {S,T} = x+y is the same is defining

stdlib/LinearAlgebra/src/symmetric.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ for (S, H) in ((:Symmetric, :Hermitian), (:Hermitian, :Symmetric))
192192
end
193193
end
194194

195-
convert(T::Type{<:Symmetric}, m::Union{Symmetric,Hermitian}) = m isa T ? m : T(m)
196-
convert(T::Type{<:Hermitian}, m::Union{Symmetric,Hermitian}) = m isa T ? m : T(m)
195+
convert(::Type{T}, m::Union{Symmetric,Hermitian}) where {T<:Symmetric} = m isa T ? m : T(m)::T
196+
convert(::Type{T}, m::Union{Symmetric,Hermitian}) where {T<:Hermitian} = m isa T ? m : T(m)::T
197197

198198
const HermOrSym{T, S} = Union{Hermitian{T,S}, Symmetric{T,S}}
199199
const RealHermSym{T<:Real,S} = Union{Hermitian{T,S}, Symmetric{T,S}}

stdlib/LinearAlgebra/src/uniformscaling.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ function show(io::IO, ::MIME"text/plain", J::UniformScaling)
118118
end
119119
copy(J::UniformScaling) = UniformScaling(J.λ)
120120

121-
Base.convert(::Type{UniformScaling{T}}, J::UniformScaling) where {T} = UniformScaling(convert(T, J.λ))
121+
Base.convert(::Type{UniformScaling{T}}, J::UniformScaling) where {T} = UniformScaling(convert(T, J.λ))::UniformScaling{T}
122122

123123
conj(J::UniformScaling) = UniformScaling(conj(J.λ))
124124
real(J::UniformScaling) = UniformScaling(real(J.λ))

stdlib/SharedArrays/src/SharedArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ function SharedArray{TS,N}(A::Array{TA,N}) where {TS,TA,N}
374374
copyto!(S, A)
375375
end
376376

377-
convert(T::Type{<:SharedArray}, a::Array) = T(a)
377+
convert(T::Type{<:SharedArray}, a::Array) = T(a)::T
378378

379379
function deepcopy_internal(S::SharedArray, stackdict::IdDict)
380380
haskey(stackdict, S) && return stackdict[S]

test/testhelpers/Furlongs.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ Base.promote_type(::Type{Furlong{p,T}}, ::Type{Furlong{p,S}}) where {p,T,S} =
2525
Furlong{p,promote_type(T,S)}
2626

2727
# only Furlong{0} forms a ring and isa Number
28-
Base.convert(::Type{T}, y::Number) where {T<:Furlong{0}} = T(y)
28+
Base.convert(::Type{T}, y::Number) where {T<:Furlong{0}} = T(y)::T
2929
Base.convert(::Type{Furlong}, y::Number) = Furlong{0}(y)
3030
Base.convert(::Type{Furlong{<:Any,T}}, y::Number) where {T<:Number} = Furlong{0,T}(y)
3131
Base.convert(::Type{T}, y::Number) where {T<:Furlong} = typeassert(y, T) # throws, since cannot convert a Furlong{0} to a Furlong{p}
3232
# other Furlong{p} form a group
33-
Base.convert(::Type{T}, y::Furlong) where {T<:Furlong{0}} = T(y)
33+
Base.convert(::Type{T}, y::Furlong) where {T<:Furlong{0}} = T(y)::T
3434
Base.convert(::Type{Furlong}, y::Furlong) = y
3535
Base.convert(::Type{Furlong{<:Any,T}}, y::Furlong{p}) where {p,T<:Number} = Furlong{p,T}(y)
36-
Base.convert(::Type{T}, y::Furlong) where {T<:Furlong} = T(y)
36+
Base.convert(::Type{T}, y::Furlong) where {T<:Furlong} = T(y)::T
3737

3838
Base.one(x::Furlong{p,T}) where {p,T} = one(T)
3939
Base.one(::Type{Furlong{p,T}}) where {p,T} = one(T)

0 commit comments

Comments
 (0)