Skip to content

Commit 95cdf9b

Browse files
Minor improvement to inference of ntuple (#54544)
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.
1 parent 9e6a29c commit 95cdf9b

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

base/ntuple.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ julia> ntuple(i -> 2*i, Val(4))
7272
if @generated
7373
:(@ntuple $N i -> f(i))
7474
else
75-
Tuple(f(i) for i = 1:N)
75+
Tuple(f(i) for i = 1:(N::Int))
7676
end
7777
end
7878
typeof(function ntuple end).name.max_methods = UInt8(5)

test/tuple.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,8 @@ end
532532
for n = 0:15
533533
@test ntuple(identity, Val(n)) == ntuple(identity, n)
534534
end
535+
536+
@test Core.Compiler.return_type(ntuple, Tuple{typeof(identity), Val}) == Tuple{Vararg{Int}}
535537
end
536538

537539
struct A_15703{N}

0 commit comments

Comments
 (0)