Skip to content

1.12-rc1 World age issue with macro #59429

@theogf

Description

@theogf

I have the following MWE of my macro redefining hash on enums:

macro new_enum(T::Symbol, args...)
   esc(quote
      @enum $T $(args...)
      function Base.hash(x::$T, h::UInt)
        rand(UInt)
      end
    end)
end

However with the new world age semantics I get the following warning introduced in #57133:

julia> @new_enum Foo A B
WARNING: Detected access to binding `Main.Foo` 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`.

It seems it the x::$T which causes the issue and I don't see how to use invokelatest here?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions