Skip to content

Staged (@generated) functions expand macros w.r.t. incorrect world #61482

@topolarity

Description

@topolarity
julia> module Generated
           macro bar()
               return :(1)
           end
           @generated function foo(x::T) where T
               return :(println("@bar: ", @bar, " (", $T, ")"))
           end
           foo(1)
           macro bar()
               return :(2)
           end
           foo(1)
           foo(1.0)
       end
@bar: 1 (Int64)
@bar: 1 (Int64)
@bar: 2 (Float64)

The @bar macro should have been expanded in the definition world of foo, but it is instead expanded in the latest world at compilation time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    correctness bug ⚠Bugs that are likely to lead to incorrect results in user code without throwing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions