Skip to content

Commit

Permalink
Minor improvement to inference of ntuple (#54544)
Browse files Browse the repository at this point in the history
In the non-`@generated` branch, where `N` may be unknown, assert its
type as `Int` so that the type of the created range can be inferred.
  • Loading branch information
martinholters authored May 23, 2024
1 parent 9e6a29c commit 95cdf9b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/ntuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ julia> ntuple(i -> 2*i, Val(4))
if @generated
:(@ntuple $N i -> f(i))
else
Tuple(f(i) for i = 1:N)
Tuple(f(i) for i = 1:(N::Int))
end
end
typeof(function ntuple end).name.max_methods = UInt8(5)
Expand Down
2 changes: 2 additions & 0 deletions test/tuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,8 @@ end
for n = 0:15
@test ntuple(identity, Val(n)) == ntuple(identity, n)
end

@test Core.Compiler.return_type(ntuple, Tuple{typeof(identity), Val}) == Tuple{Vararg{Int}}
end

struct A_15703{N}
Expand Down

0 comments on commit 95cdf9b

Please sign in to comment.