JuliaLang / julia

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

`redirect_stderr` does not redirect method overwritten warnings #56667

Open LilithHafner opened 2 days ago

LilithHafner commented 2 days ago
$julia -q --warn-overwrite=yes
julia> f() = 1
f (generic function with 1 method)

julia> g() = @eval f() = 1
g (generic function with 1 method)

julia> g()
WARNING: Method definition f() in module Main at REPL[1]:1 overwritten at REPL[2]:1.
f (generic function with 1 method)

julia> redirect_stderr(g, devnull)
WARNING: Method definition f() in module Main at REPL[2]:1 overwritten on the same line (check for duplicate calls to `include`).
f (generic function with 1 method)
LilithHafner commented 2 days ago

A workaround for suppressing these warnings is

julia> x = Base.JLOptions().warn_overwrite
0x01

julia> unsafe_store!(reinterpret(Ptr{UInt8}, cglobal(:jl_options, Base.JLOptions)), 0x00, fieldoffset(Base.JLOptions, findfirst(==(:warn_overwrite), fieldnames(Base.JLOptions)))+1)
Ptr{UInt8} @0x0000fffec7b91ea8

julia> g()

julia> unsafe_store!(reinterpret(Ptr{UInt8}, cglobal(:jl_options, Base.JLOptions)), x, fieldoffset(Base.JLOptions, findfirst(==(:warn_overwrite), fieldnames(Base.JLOptions)))+1)
Ptr{UInt8} @0x0000fffec7b91ea8

julia> g()
WARNING: Method definition f() in module Main at REPL[27]:1 overwritten on the same line (check for duplicate calls to `include`).
IanButterworth commented 2 days ago

I tried to fix this here https://github.com/JuliaLang/julia/pull/55958