@@ -338,62 +338,73 @@ same_value_and_type(x::T, y::T) where {T} = (x === y) || (x == y)
338338 @testset " convert_eltype()" begin
339339 # Numbers.
340340 let A = rand (Float64), B = @inferred convert_eltype (Float32, A)
341- @test convert_eltype (eltype (A), A) === A
341+ @test A === @inferred convert_eltype (eltype (A), A)
342342 @test B isa Float32
343343 @test B == Float32 .(A)
344+ @test typeof (B) === @inferred convert_eltype (eltype (B), typeof (A))
344345 end
345346 # Abstract arrays.
346347 let A = rand (Float64, 2 , 3 ), B = @inferred convert_eltype (Float32, A)
347- @test convert_eltype (eltype (A), A) === A
348+ @test A === @inferred convert_eltype (eltype (A), A)
348349 @test B isa AbstractArray{Float32,ndims (A)}
349350 @test B == Float32 .(A)
351+ @test typeof (B) === @inferred convert_eltype (eltype (B), typeof (A))
352+ @test AbstractArray{UInt8,2 } === @inferred convert_eltype (UInt8, typeof (view (A,:,1 : 2 : 3 )))
350353 end
351354 # Base.OneTo
352355 let A = OneTo {Int32} (7 ), B = @inferred convert_eltype (Int16, A)
353- @test convert_eltype (eltype (A), A) === A
356+ @test A === @inferred convert_eltype (eltype (A), A)
354357 @test B isa OneTo{Int16}
355358 @test B == Int16 .(A)
359+ @test typeof (B) === @inferred convert_eltype (eltype (B), typeof (A))
356360 end
357361 let A = OneTo (7 ), B = @inferred convert_eltype (Float32, A)
358- @test convert_eltype (eltype (A), A) === A
362+ @test A === @inferred convert_eltype (eltype (A), A)
359363 @test B isa AbstractRange{Float32}
360364 @test B == Float32 .(A)
365+ @test typeof (B) === @inferred convert_eltype (eltype (B), typeof (A))
361366 end
362367 # UnitRange
363368 let A = 2 : 8 , B = @inferred convert_eltype (Float32, A)
364- @test convert_eltype (eltype (A), A) === A
369+ @test A === @inferred convert_eltype (eltype (A), A)
365370 @test B isa AbstractRange{Float32}
366371 @test B == Float32 .(A)
372+ @test typeof (B) === @inferred convert_eltype (eltype (B), typeof (A))
367373 end
368374 # OrdinalRange
369375 let A = 2.0 : 3.0 : 11.0 , B = @inferred convert_eltype (Float32, A)
370- @test convert_eltype (eltype (A), A) === A
376+ @test A === @inferred convert_eltype (eltype (A), A)
371377 @test B isa AbstractRange{Float32}
372378 @test B == Float32 .(A)
379+ @test typeof (B) < : @inferred convert_eltype (eltype (B), typeof (A))
373380 end
374381 # LinRange
375382 let A = LinRange (- 2.0 , 3.0 , 5 ), B = @inferred convert_eltype (Float32, A)
376- @test convert_eltype (eltype (A), A) === A
383+ @test A === @inferred convert_eltype (eltype (A), A)
377384 @test B isa LinRange{Float32}
378385 @test B == Float32 .(A)
386+ @test typeof (B) < : @inferred convert_eltype (eltype (B), typeof (A))
379387 end
380388 # Tuples.
381389 let A = (1 , 2 , 3 ) #= NTuple =# , B = @inferred convert_eltype (Float32, A)
382- @test convert_eltype (eltype (A), A) === A
383- @test B isa NTuple{<: Any ,Float32}
390+ @test A === @inferred convert_eltype (eltype (A), A)
391+ @test B isa NTuple{3 ,Float32}
384392 @test B == Float32 .(A)
393+ @test typeof (B) === @inferred convert_eltype (Float32, typeof (A))
385394 end
386- let A = (1 , 2.0 , 3 ) #= not NTuple but Tuple =# , B = @inferred convert_eltype (Float32, A)
387- @test convert_eltype (eltype (A), A) === A
388- @test B isa NTuple{<: Any ,Float32}
395+ let A = (1 , 2.0 , pi ) #= not NTuple but Tuple =# , B = @inferred convert_eltype (Float32, A)
396+ @test A === @inferred convert_eltype (eltype (A), A)
397+ @test B isa NTuple{3 ,Float32}
389398 @test B == Float32 .(A)
399+ @test typeof (B) === @inferred convert_eltype (Float32, typeof (A))
390400 end
391401 # Map `convert_eltype`.
392402 let A = rand (Float64, 2 , 3 ), B = reshape (1 : 12 , 3 , 4 )
393403 f = @inferred convert_eltype (Float32)
394404 @test isequal (f (A), convert_eltype (Float32, A))
395405 @test isequal (f (B), convert_eltype (Float32, B))
396406 end
407+ @test_throws ErrorException convert_eltype (Char, String)
397408 end
398409
399410 @testset " as_eltype()" begin
0 commit comments