World age warning (no @eval) on constructor of different dispatch

Updated to julia-1.12 and started a new package. As soon as I defined my first struct with more than one external constructor (nothing fancy, no @evals), I’ve got the world age warning (future error).

MWE:

struct example
    pos::String
    per::Char
    # Internal (validating) constructor
    function example(pos::S, per::C='-') where {S<:AbstractString, C<:AbstractChar}
        @assert pos in ("RA", "RD")
        @assert per in "-123"
        return new(pos, per)
    end
end

export example

# The first external constructor works fine
example(pos::S, par::S) where S<:AbstractString = example(pos, par...)
# Next line raises warning
example(all::S) where S<:AbstractString = example(split(all, ' ')...)

Basically these constructors allows for convenient syntax in the particular field of application, which does not pertain to the issue/MWE.

Upon precompiling (using in the REPL), the last line, which defines the only one-argument constructor (which should be fine given julia’s multiple dispatch), causes a WARNING: Method definition to be issued (twice!) saying the validating constructor got redefined (which doesn’t make sense, due to different dispatch), along with:

WARNING: Detected access to binding `XXXX.example` in a world prior to its definition world.
  Julia 1.12 has introduced more strict world age semantics for global bindings.
  !!! This code may malfunction under Revise.
  !!! This code will error in future versions of Julia.
Hint: Add an appropriate `invokelatest` around the access to this binding.
To make this warning an error, and hence obtain a stack trace, use `julia --depwarn=error`.

Since it will become an error, I did some research and my case seems NOT to relate with the things I see (i) in the documentation, (ii) julia’s open issues, or (iii) this forum.

It issues warning but it works as intended:

julia> example("RA", '1')
example("RA", '1')

julia> example("RA", "1")
example("RA", '1')

julia> example("RA 1")
example("RA", '1')
  1. What is really the issue?
  2. What would be the “appropriate” invokelatests syntax to fix this as per suggestion? As
example(all::S) where S<:AbstractString = invokelatest(example(split(all, ' ')...))

did not work at all and further introduce the error:

julia> example("RA 1")
ERROR: MethodError: objects of type example are not callable
The object of type `example` exists, but no method is defined for this combination of argument types when
 trying to treat it as a callable object.
Stacktrace:
 [1] example(all::String)
   @ GNTParsings /home/BACK/trendy/local/dev/GNTParsings.jl/src/types.jl:21
 [2] top-level scope
   @ REPL[4]:1
1 Like

You’re overwriting the one argument version of the internal constructor. As for why you’re getting the world age warning, that’s probably a bug with the warning for this case running in the wrong world age.

3 Likes

I pasted that in an old HelloWorld tutorial package, activated it, and imported it for a quick experiment on v1.12.5 (Windows). I’m seeing the 2 method definition warnings, but I’m not seeing the world age warning, so I’m assuming there’s some difference from GNTParsings or its environment. The 2 method definition warnings went by pretty fast so I haphazardly threw in a print("Hello precompile") before the export line. It showed up 3 times adjacent to the 2 warnings; the last run could be the non-precompiling eval that lets the subsequent example calls work, so precompilation appears to be happening before each warning.

1 Like

Ahh, snap! because of the default argument in

function example(pos::S, per::C='-') where {S<:AbstractString, C<:AbstractChar}

Tried removing it and it worked (no warnings at all). Thank you!

That’s what happens when you switch among different languages of completely different paradigms!

It should be nevertheless noted that the world age warning placed me in the wrong track (likely my fault, as I should’ve taken more heed to the previous method overwriting warning).

Thanks for your effort in reconstructing the scenario and testing!

You added to the world age issue by pointing it’s absence in Windows (I use a Linux box), and yes, we’re running the same version of julia: Version 1.12.5 (2026-02-09)

I do agree, but it would be helpful if you could provide a full MWE. Claude was unable to reproduce it as stated.