Disallow construction of NTuple from > N elements
Currently, you can construct NTuples for any iterable with more than N elements:
julia> NTuple{1}("hello")
('h',)
julia> NTuple{3}(1:5)
(1, 2, 3)
This strikes me as problematic, and an easy way of getting into trouble. If the user tries to create NTuple from something with more than N elements, they probably made a mistake. It would be much nicer if it behaved like:
julia> NTuple{3}(1:5)
ERROR: ArgumentError: too many elements for tuple type Tuple{T} where T
Stacktrace:
[1] _totuple_err(T::Any)
@ Base ./tuple.jl:309
(or similar). In practice, this could be done by simply verifying that the iterator returns nothing before returning the tuple.
This change is breaking, but it may be worth considering for a future, breaking release, but perhaps the issue can be solved in a non-breaking way somehow.
Related: https://github.com/JuliaLang/julia/issues/37132
This is only "breaking" in the sense that fixing it could break some user code that depends on the current, buggy, behavior; however the buggy behavior was never documented. So I think the buggy behavior is not supported and I don't think that fixing it should necessarily be considered as breaking. Does Julia have some backwards compatibility promise document? Perhaps such a document would have answers to questions like this one, if it exists?
essentially a duplicate of https://github.com/JuliaLang/julia/issues/18312, although they examine different consequences so maybe both should be left open