Skip to content

Commit

Permalink
Add type assertion to inner HermOrSym constructor (JuliaLang#50282)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkarrasch committed Jun 26, 2023
1 parent ed338d0 commit d01b8cd
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 2 additions & 2 deletions stdlib/LinearAlgebra/src/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ struct Symmetric{T,S<:AbstractMatrix{<:T}} <: AbstractMatrix{T}
data::S
uplo::Char

function Symmetric{T,S}(data, uplo) where {T,S<:AbstractMatrix{<:T}}
function Symmetric{T,S}(data, uplo::Char) where {T,S<:AbstractMatrix{<:T}}
require_one_based_indexing(data)
(uplo != 'U' && uplo != 'L') && throw_uplo()
new{T,S}(data, uplo)
Expand Down Expand Up @@ -98,7 +98,7 @@ struct Hermitian{T,S<:AbstractMatrix{<:T}} <: AbstractMatrix{T}
data::S
uplo::Char

function Hermitian{T,S}(data, uplo) where {T,S<:AbstractMatrix{<:T}}
function Hermitian{T,S}(data, uplo::Char) where {T,S<:AbstractMatrix{<:T}}
require_one_based_indexing(data)
(uplo != 'U' && uplo != 'L') && throw_uplo()
new{T,S}(data, uplo)
Expand Down
3 changes: 3 additions & 0 deletions stdlib/LinearAlgebra/test/symmetric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ end
@test_throws ArgumentError Symmetric(asym, :R)
@test_throws ArgumentError Hermitian(asym, :R)

@test_throws MethodError Symmetric{eltya,typeof(asym)}(asym, :L)
@test_throws MethodError Hermitian{eltya,typeof(aherm)}(aherm, :L)

# mixed cases with Hermitian/Symmetric
if eltya <: Real
@test Symmetric(Hermitian(aherm, :U)) === Symmetric(aherm, :U)
Expand Down

0 comments on commit d01b8cd

Please sign in to comment.