Revise.jl icon indicating copy to clipboard operation
Revise.jl copied to clipboard

"world prior to its definition" warning when modifying struct

Open tpapp opened this issue 7 months ago • 2 comments

I was working on some code in Julia 1.12.0-beta3, using Revise 3.8.0. Specifically on a section

struct Shift{T <: AbstractVector}
    irrelevant_field::Int # for the MWE
    b::T
end

shift(b::AbstractVector) = Shift(b)

within a package.

I modified the type Shift deleting irrelevant_field and after evaluating something in the REPL, I got

WARNING: Detected access to binding `LogDensityTestSuite.shift` 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`.

But everything seems to work fine, shift has the right methods, etc.

tpapp avatar May 29 '25 10:05 tpapp

In addition to the warning above, I managed to run into an actual error when redefining a struct.

When deleting the {L} from a type defined like

struct Funnel{L} <: LogDensityTransformation end

so that the new code is

struct Funnel <: LogDensityTransformation end

a method with signature source_to_destination(transformation::Funnel, x) cannot be found, with error

ERROR: MethodError: no method matching source_to_destination(::LogDensityTestSuite.Funnel, ::Vector{Float64})
The function `source_to_destination` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  source_to_destination(::@world(LogDensityTestSuite.Funnel, 38767:38780), ::Any)
   @ LogDensityTestSuite ~/code/julia/LogDensityTestSuite/src/transformations.jl:270

If the error is not apparent, I can try to come up with an MWE.

tpapp avatar May 29 '25 13:05 tpapp

You'll need #894.

timholy avatar Jul 23 '25 00:07 timholy