Skip to content

Commit 2e30721

Browse files
committed
Inference works for much more arguments
1 parent 2570607 commit 2e30721

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
- Methods `as(T)`, `nearest(T)`, `convert_bare_type(T)`, `convert_real_type(T)`,
1010
`convert_floating_point_type(T)`, and `convert_eltype(T)` yield converters to type `T`.
1111

12+
- Inference works for more than 3 arguments for `bare_type(args...)`,
13+
`real_type(args...)`, and `floating_point_type(args...)`.
14+
1215
# Version 1.4.2
1316

1417
- New `nearest(T,x)` method to return the value of type `T` that is the nearest to `x`.

src/TypeUtils.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,7 +738,7 @@ for f in (:bare_type, :real_type)
738738
@eval begin
739739
$f(a, b) = promote_type($f(a), $f(b))
740740
$f(a, b, c) = promote_type($f(a), $f(b), $f(c))
741-
@inline $f(a, b, c...) = promote_type($f(a), $f(b), map($f, c)...)
741+
@inline $f(a, b, c...) = promote_type($f(a, b), $f(c...))
742742
end
743743
end
744744

test/runtests.jl

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -121,15 +121,15 @@ same_value_and_type(x::T, y::T) where {T} = (x === y) || (x == y)
121121
@test (2:5, -1:4) === @inferred as(Tuple, CartesianIndices((2:5, -1:4)))
122122
@test (2:5, -1:4) === @inferred as(NTuple{2}, CartesianIndices((2:5, -1:4)))
123123

124-
@test CartesianIndex() === @inferred as(CartesianIndex,())
124+
@test CartesianIndex() === @inferred as(CartesianIndex,())
125125
@test CartesianIndex((1,2,3)) === @inferred as(CartesianIndex, CartesianIndex((1,2,3)))
126126
@test CartesianIndex((1,2,3)) === @inferred as(CartesianIndex{3}, CartesianIndex((1,2,3)))
127127
@test CartesianIndex((1,2,3)) === @inferred as(CartesianIndex, (0x1,2,Int16(3)))
128128
@test CartesianIndex((1,2,3)) === @inferred as(CartesianIndex{3}, (0x1,2,Int16(3)))
129129

130-
@test CartesianIndices(()) === @inferred as(CartesianIndices,())
131-
@test CartesianIndices((2:3,6)) === @inferred as(CartesianIndices,(2:3,6))
132-
@test CartesianIndices((2:3,6)) === @inferred as(CartesianIndices,CartesianIndices((2:3,6)))
130+
@test CartesianIndices(()) === @inferred as(CartesianIndices,())
131+
@test CartesianIndices((2:3,6)) === @inferred as(CartesianIndices,(2:3,6))
132+
@test CartesianIndices((2:3,6)) === @inferred as(CartesianIndices,CartesianIndices((2:3,6)))
133133
@test CartesianIndices((2:3,6,-1:4)) === @inferred as(CartesianIndices{3},(2:3,6,-1:4))
134134
@test CartesianIndices((2:3,6,-1:4)) === @inferred as(CartesianIndices{3},CartesianIndices((2:3,6,-1:4)))
135135

@@ -527,12 +527,13 @@ same_value_and_type(x::T, y::T) where {T} = (x === y) || (x == y)
527527
@test_throws ErrorException bare_type(AbstractString)
528528

529529
# bare_type with multiple arguments
530-
@test Float32 === @inferred bare_type(1, 0f0)
531-
@test promote_type(Int, typeof(pi)) === @inferred bare_type(Int, pi)
532-
@test promote_type(Int, typeof(pi), Float64) === @inferred bare_type(4, pi, 1.0)
533-
@test promote_type(Int, Int8, Float32) === @inferred bare_type(Int, Int8, Float32)
534-
@test promote_type(Int, Int8, Float32) === @inferred bare_type(Int, Int8, Float32)
535-
@test promote_type(Int, Int8, Int16, Float32) === #=@inferred=# bare_type(Int, Int8, Int16, Float32)
530+
@test Float32 === @inferred bare_type(1, 0f0)
531+
@test promote_type(Int, typeof(pi)) === @inferred bare_type(Int, pi)
532+
@test promote_type(Int, typeof(pi), Float64) === @inferred bare_type(4, pi, 1.0)
533+
@test promote_type(Int, Int8, Float32) === @inferred bare_type(Int, Int8, Float32)
534+
@test promote_type(Int, Int8, Int16, Float32) === @inferred bare_type(Int, Int8, Int16, Float32)
535+
@test promote_type(Int, Int8, Int16, Float32, Bool) === @inferred bare_type(Int, Int8, Int16, Float32, Bool)
536+
@test promote_type(Int, Int8, Int16, Float32, Bool, UInt16) === @inferred bare_type(Int, Int8, Int16, Float32, Bool, UInt16)
536537

537538
# default implementation
538539
@test Float32 === @inferred bare_type(MyNumber(1.2f0))
@@ -583,12 +584,14 @@ same_value_and_type(x::T, y::T) where {T} = (x === y) || (x == y)
583584
@test_throws ErrorException real_type(AbstractString)
584585

585586
# real_type with multiple arguments
586-
@test Float32 === @inferred real_type(1, 0f0)
587-
@test promote_type(Int, typeof(pi)) === @inferred real_type(Int, pi)
588-
@test promote_type(Int, typeof(pi), Float64) === @inferred real_type(4, pi, 1.0)
589-
@test promote_type(Int, Int8, Float32) === @inferred real_type(Int, Int8, Float32)
590-
@test promote_type(Int, Int8, Float32) === @inferred real_type(Int, Int8, Float32)
591-
@test promote_type(Int, Int8, Int16, Float32) === #=@inferred=# real_type(Int, Int8, Complex{Int16}, Float32)
587+
@test Float32 === @inferred real_type(1, 0f0)
588+
@test promote_type(Int, typeof(pi)) === @inferred real_type(Int, pi)
589+
@test promote_type(Int, typeof(pi), Float64) === @inferred real_type(4, pi, 1.0)
590+
@test promote_type(Int, Int8, Float32) === @inferred real_type(Int, Int8, Float32)
591+
@test promote_type(Int, Int8, Int16, Float32) === @inferred real_type(Int, Int8, Int16, Float32)
592+
@test promote_type(Int, Int8, Int16, Float32, Bool) === @inferred real_type(Int, Int8, Int16, Float32, Bool)
593+
@test promote_type(Int, Int8, Int16, Float32, Bool, UInt16) === @inferred real_type(Int, Int8, Int16, Float32, Bool, UInt16)
594+
@test promote_type(Int, Int8, Int16, Float32, Bool, UInt16) === @inferred real_type(Int, Int8, Int16, Complex{Float32}, Bool, UInt16)
592595

593596
# default implementation
594597
@test Float32 === @inferred real_type(MyNumber(1.2f0))
@@ -630,7 +633,8 @@ same_value_and_type(x::T, y::T) where {T} = (x === y) || (x == y)
630633
@test float(Int16) === @inferred floating_point_type(Int16)
631634
@test Float32 === @inferred floating_point_type(Int16, Float32)
632635
@test Float64 === @inferred floating_point_type(Int16, Float32, Complex{Float64})
633-
@test Float32 === #=@inferred=# floating_point_type(Int16, Float32, Complex{Float16}, 0x1)
636+
@test Float32 === @inferred floating_point_type(Int16, Float32, Complex{Float16}, 0x1)
637+
@test Float32 === @inferred floating_point_type(Int16, Float32, Complex{Float16}, 0x1, -42)
634638

635639
# convert_floating_point_type
636640
@test -1.0 === @inferred convert_floating_point_type(Int, -1)

0 commit comments

Comments
 (0)