From 980b83d3f8703f3dd0ee03df8a6916364265baef Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Thu, 25 Jul 2024 05:48:10 -0400 Subject: [PATCH] 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 ae483c352273af392e1dd6bd2cb3b044ffa46111) --- base/abstractarray.jl | 2 +- test/abstractarray.jl | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 7be13ad34a66d..d7ef5e2b69f2b 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -2891,7 +2891,7 @@ end @inline function _stack_size_check(x, ax1::Tuple) if _iterator_axes(x) != ax1 uax1 = map(UnitRange, ax1) - uaxN = map(UnitRange, axes(x)) + uaxN = map(UnitRange, _iterator_axes(x)) throw(DimensionMismatch( LazyString("stack expects uniform slices, got axes(x) == ", uaxN, " while first had ", uax1))) end diff --git a/test/abstractarray.jl b/test/abstractarray.jl index 9691db88b6e99..8d0c83897611b 100644 --- a/test/abstractarray.jl +++ b/test/abstractarray.jl @@ -1684,6 +1684,9 @@ end @test_throws ArgumentError stack([1:3, 4:6]; dims=3) @test_throws ArgumentError stack(abs2, 1:3; dims=2) + @test stack(["hello", "world"]) isa Matrix{Char} + @test_throws DimensionMismatch stack(["hello", "world!"]) # had a bug in error printing + # Empty @test_throws ArgumentError stack(()) @test_throws ArgumentError stack([])