JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.43k stars 5.45k forks source link

Possible improvement in error messages for invalid array sizes #55446

Open jishnub opened 1 month ago

jishnub commented 1 month ago
julia> zeros(-1)
ERROR: ArgumentError: invalid GenericMemory size: too large for system address width
Stacktrace:
 [1] GenericMemory
   @ ./boot.jl:538 [inlined]
 [2] Array
   @ ./boot.jl:598 [inlined]
 [3] Array
   @ ./boot.jl:611 [inlined]
 [4] zeros
   @ ./array.jl:579 [inlined]
 [5] zeros
   @ ./array.jl:576 [inlined]
 [6] zeros(dims::Int64)
   @ Base ./array.jl:574
 [7] top-level scope
   @ REPL[1]:1

julia> versioninfo()
Julia Version 1.12.0-DEV.1034
Commit 7e809b0953c (2024-08-10 04:31 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: 8 × Intel(R) Core(TM) i5-10310U CPU @ 1.70GHz
  WORD_SIZE: 64
  LLVM: libLLVM-18.1.7 (ORCJIT, skylake)
Threads: 1 default, 0 interactive, 1 GC (on 8 virtual cores)
Environment:
  JULIA_EDITOR = subl

The message here might be a bit clearer, and point to the fact that the size cannot be negative.

longemen3000 commented 4 weeks ago

The error stems from here: https://github.com/JuliaLang/julia/blob/0a26e908e77f147a5a964735ad02f74d047fe47b/src/genericmemory.c#L159