Skip to content

Commit b420a6d

Browse files
authored
slightly better type inference for reverse(::NTuple) (#55394)
Before the return type of `reverse(::NTuple)` inferred as `Tuple`, now it's more precise, inferring as `NTuple`. This is a partial reland of #55124 and partial revert of #55375. Fixes #54495
1 parent 040f6cd commit b420a6d

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

base/ntuple.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,5 +90,5 @@ end
9090
function reverse(t::NTuple{N}) where N
9191
ntuple(Val{N}()) do i
9292
t[end+1-i]
93-
end
93+
end::typeof(t)
9494
end

test/tuple.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -858,3 +858,6 @@ end
858858
end
859859
end
860860
end
861+
862+
@test NTuple == Base.infer_return_type(reverse, Tuple{NTuple})
863+
@test Tuple{Vararg{Int}} == Base.infer_return_type(reverse, Tuple{Tuple{Vararg{Int}}})

0 commit comments

Comments
 (0)