Skip to content

Commit 70a23a6

Browse files
committed
Show index earlier in throw_nonzeroerror
1 parent b19d33b commit 70a23a6

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

src/triangular.jl

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -278,12 +278,17 @@ Base.@constprop :aggressive @propagate_inbounds function getindex(A::Union{Lower
278278
end
279279
end
280280

281-
@noinline function throw_nonzeroerror(Tn, @nospecialize(x), i, j)
282-
Ts = Tn in (:UpperTriangular, :UnitUpperTriangular) ? "lower" : "upper"
281+
@noinline function throw_nonzeroerror(Tn::Symbol, @nospecialize(x), i, j)
282+
zero_half = Tn in (:UpperTriangular, :UnitUpperTriangular) ? "lower" : "upper"
283+
nstr = Tn === :UpperTriangular ? "n" : ""
283284
throw(ArgumentError(
284-
lazy"cannot set index in the $Ts triangular part ($i, $j) of a $Tn matrix to a nonzero value ($x)"))
285+
LazyString(
286+
lazy"cannot set index ($i, $j) in the $zero_half triangular part ",
287+
lazy"of a$nstr $Tn matrix to a nonzero value ($x)")
288+
)
289+
)
285290
end
286-
@noinline function throw_nonuniterror(Tn, @nospecialize(x), i, j)
291+
@noinline function throw_nonuniterror(Tn::Symbol, @nospecialize(x), i, j)
287292
throw(ArgumentError(
288293
lazy"cannot set index ($i, $j) on the diagonal of a $Tn matrix to a non-unit value ($x)"))
289294
end

test/triangular.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,11 +641,11 @@ end
641641
@testset "error message" begin
642642
A = UpperTriangular(Ap)
643643
B = UpperTriangular(Bp)
644-
@test_throws "cannot set index in the lower triangular part" copyto!(A, B)
644+
@test_throws "cannot set index (3, 1) in the lower triangular part" copyto!(A, B)
645645

646646
A = LowerTriangular(Ap)
647647
B = LowerTriangular(Bp)
648-
@test_throws "cannot set index in the upper triangular part" copyto!(A, B)
648+
@test_throws "cannot set index (1, 2) in the upper triangular part" copyto!(A, B)
649649
end
650650
end
651651

0 commit comments

Comments
 (0)