Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand eats the body of functions in a quoted module expression #12075

Closed
vtjnash opened this issue Jul 8, 2015 · 2 comments
Closed

expand eats the body of functions in a quoted module expression #12075

vtjnash opened this issue Jul 8, 2015 · 2 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior

Comments

@vtjnash
Copy link
Sponsor Member

vtjnash commented Jul 8, 2015

expand should not be walking through the body of modules, since it ends up expanding in the wrong scope:

julia> expand(quote
                       module A
                        __init__() = 2
                       end
                     end)
:(begin  # none, line 2:
        return module A
            $(Expr(:method, :eval, :((top(svec))((top(apply_type))(Tuple,Any),(top(svec))())), AST(:($(Expr(:lambda, Any[:x], Any[Any[Any[:x,:Any,0]],Any[],0,Any[]], :(begin  # none, line 2:
        ((top(getfield))(top(Core),:eval))(A,x)
    end))))), false))
            $(Expr(:method, :eval, :((top(svec))((top(apply_type))(Tuple,Any,Any),(top(svec))())), AST(:($(Expr(:lambda, Any[:m,:x], Any[Any[Any[:m,:Any,0],Any[:x,:Any,0]],Any[],0,Any[]], :(begin  # none, line 2:
        ((top(getfield))(top(Core),:eval))(m,x)
    end))))), false)) # line 3:
            $(Expr(:method, :__init__, :((top(svec))((top(apply_type))(Tuple),(top(svec))())), AST(:($(Expr(:lambda, Any[], Any[Any[],Any[],0,Any[]], :(begin  # none, line 3:
    end))))), false))
            end
    end)

it does the right thing when the module is quoted differently:

julia> expand(:(
                       module A
                        __init__() = 2
                       end
                     ))
:(module A
    eval(x) = begin  # none, line 2:
            top(Core).eval(A,x)
        end
    eval(m,x) = begin  # none, line 2:
            top(Core).eval(m,x)
        end # line 3:
    __init__() = begin  # none, line 3:
            2
        end
    end)
@vtjnash vtjnash added the bug Indicates an unexpected problem or unintended behavior label Jul 8, 2015
@vtjnash
Copy link
Sponsor Member Author

vtjnash commented Jul 21, 2015

it still differs on macro expansion behavior:

julia> eval(Main,quote
       module A
       import Base.Test.@test
       @test true
       end
       end)
ERROR: UndefVarError: @test not defined

julia> eval(Main,:(
       module A
       import Base.Test.@test
       @test true
       end
       ))
A

@vtjnash vtjnash reopened this Jul 21, 2015
@JeffBezanson
Copy link
Sponsor Member

Fair enough; I will give you a different error message :P

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

2 participants