Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding methods to eval or include throws in v1.12 #57070

Open
nickrobinson251 opened this issue Jan 16, 2025 · 3 comments
Open

Adding methods to eval or include throws in v1.12 #57070

nickrobinson251 opened this issue Jan 16, 2025 · 3 comments

Comments

@nickrobinson251
Copy link
Contributor

...if the function name isn't fully qualified or explicity imported

e.g.

> julia +nightly -q --startup-file=no
julia> VERSION
v"1.12.0-DEV.1898"

julia> eval(::Int) = 42
ERROR: cannot define function eval; it already has a value
Stacktrace:
 [1] top-level scope
   @ none:0
 [2] top-level scope
   @ REPL[2]:1

julia> include(::Int) = 0
ERROR: cannot define function include; it already has a value
Stacktrace:
 [1] top-level scope
   @ none:0
 [2] top-level scope
   @ REPL[3]:1

julia> Base.eval(::Int) = 42  # works

julia> Base.include(::Int) = 0  # works

Note the error message is different from trying to extend other methods without qualification e.g.

julia> VERSION
v"1.12.0-DEV.1898"

julia> 1+2  # so Base.+ has been used
3

julia> +(::String) = 42
ERROR: invalid method definition in Main: function Base.+ must be explicitly imported to be extended
Stacktrace:
 [1] top-level scope
   @ none:0
 [2] top-level scope
   @ REPL[3]:1

Whereas in v1.11

nickr@RAI-Mac ~/r/r/p/Tropea> julia +1.11 -q --startup-file=no
julia> VERSION
v"1.11.2"

julia> eval(::Int) = 42
eval (generic function with 2 methods)

julia> include(::Int) = 0
include (generic function with 3 methods)

Was this a deliberate change?

It broke some of our code that happened to use the name eval (not meaning to extend Base.eval), so wanted to check the new behaviour was intended

@mbauman
Copy link
Member

mbauman commented Jan 16, 2025

This is certainly due to #55949. Unlike +, eval and include are (and have been) local definitions in the module. Previously, you were modifying the function table for that module's machinery and not doing any shadowing as you may have expected.

@NHDaly
Copy link
Member

NHDaly commented Jan 16, 2025

🤔 so technically #55949 was a breaking change then, since it has now essentially made eval and include into reserved names, and a package cannot provide functions called eval or include.

This is maybe okay, but it's a breaking change. Eval, in particular, could be a useful name for packages like solvers?
For example: DACE.eval

@nsajko
Copy link
Contributor

nsajko commented Jan 17, 2025

a package cannot provide functions called eval or include

Not true, it's still possible to define a new function named eval or include. This is as before, by using baremodule in place of module:

julia> baremodule M
           function eval end
           function include end
       end
Main.M

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants