-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed as not planned
Milestone
Description
Consider the following generated function:
@generated function constructorof(::Type{T}) where T
getfield(parentmodule(T), nameof(T))
endThis should (at least from what I can see) be an ok generated function considering the current restrictions the docs places on them. It only calls functions defined before the function and it only reads global constants. However, it currently gives a warning
julia> struct Foo end
julia> constructorof(Foo)
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.
FooSo it seems that there is an additional restriction to generated functions now in that it is only allowed to read a global constant defined before the generated function. If that is the case, the documentation should be updated.
A lot of code in e.g. ConstructionBase uses this pattern:
serenity4 and rfourquet
Metadata
Metadata
Assignees
Labels
No labels