Skip to content

Commit 980b83d

Browse files
mcabbottKristofferC
authored and
KristofferC
committed
Fix a bug in stack's DimensionMismatch error message (#54033)
`stack` does not require that the inner iterator defines `axes`, but the code to assemble an error message assumed this. Found here: https://discourse.julialang.org/t/reduce-hcat-is-type-unstable/112800/3 (cherry picked from commit ae483c3)
1 parent f91f502 commit 980b83d

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

base/abstractarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2891,7 +2891,7 @@ end
28912891
@inline function _stack_size_check(x, ax1::Tuple)
28922892
if _iterator_axes(x) != ax1
28932893
uax1 = map(UnitRange, ax1)
2894-
uaxN = map(UnitRange, axes(x))
2894+
uaxN = map(UnitRange, _iterator_axes(x))
28952895
throw(DimensionMismatch(
28962896
LazyString("stack expects uniform slices, got axes(x) == ", uaxN, " while first had ", uax1)))
28972897
end

test/abstractarray.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,9 @@ end
16841684
@test_throws ArgumentError stack([1:3, 4:6]; dims=3)
16851685
@test_throws ArgumentError stack(abs2, 1:3; dims=2)
16861686

1687+
@test stack(["hello", "world"]) isa Matrix{Char}
1688+
@test_throws DimensionMismatch stack(["hello", "world!"]) # had a bug in error printing
1689+
16871690
# Empty
16881691
@test_throws ArgumentError stack(())
16891692
@test_throws ArgumentError stack([])

0 commit comments

Comments
 (0)