From d82a82286f4107e1dbe740cd5da9171dd57b5a5a Mon Sep 17 00:00:00 2001 From: Tim Holy Date: Thu, 18 Aug 2016 17:22:30 -0500 Subject: [PATCH] Test that similar throws a MethodError for unsupported dims types --- test/offsetarray.jl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/test/offsetarray.jl b/test/offsetarray.jl index 6d99433d03d61..2e8c16d1bc3c6 100644 --- a/test/offsetarray.jl +++ b/test/offsetarray.jl @@ -166,6 +166,21 @@ B = similar(A, (-3:3,1:4)) B = similar(parent(A), (-3:3,1:4)) @test isa(B, OffsetArray{Int,2}) @test indices(B) === (-3:3, 1:4) +# Check that similar throws a MethodError rather than a +# StackOverflowError if no appropriate method has been defined +# (#18107) +module SimilarUR + immutable MyURange <: AbstractUnitRange{Int} + start::Int + stop::Int + end + ur = MyURange(1,3) + a = Array{Int}(2) + @test_throws MethodError similar(a, ur) + @test_throws MethodError similar(a, Float64, ur) + @test_throws MethodError similar(a, Float64, (ur,)) + @test_throws MethodError similar(a, (2.0,3.0)) +end # Indexing with OffsetArray indices i1 = OffsetArray([2,1], (-5,))