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

"LoadError: MethodError: Cannot convert an object of type Expr to an object of type Symbol" when using @bounce on multiline function definitions #123

Open
uribalb opened this issue Sep 22, 2020 · 0 comments

Comments

@uribalb
Copy link

uribalb commented Sep 22, 2020

When I execute this, for example (Jupyter Notebook):

@bounce function pair(n) 
    return n > 1 ? pair(n - 2)  : 1 - n
end

I get the following error:

LoadError: MethodError: Cannot `convert` an object of type Expr to an object of type Symbol
Closest candidates are:
  convert(::Type{T}, !Matched::T) where T at essentials.jl:171
  Symbol(::Any...) at strings/basic.jl:227
in expression starting at In[136]:1
Stacktrace:
 [1] push!(::Array{Symbol,1}, ::Expr) at .\array.jl:934
 [2] (::Lazy.var"#17#18"{Array{Symbol,1}})(::Expr) at C:\Users\username\.julia\packages\Lazy\9Xnd3\src\tail.jl:128
 [3] macro expansion at C:\Users\username\.julia\packages\Lazy\9Xnd3\src\tail.jl:44 [inlined]
 [4] macro expansion at C:\Users\username\.julia\packages\MacroTools\X77lQ\src\match\macro.jl:18 [inlined]
 [5] lastcalls(::Lazy.var"#17#18"{Array{Symbol,1}}, ::Expr) at C:\Users\username\.julia\packages\Lazy\9Xnd3\src\tail.jl:7
 [6] macro expansion at C:\Users\username\.julia\packages\Lazy\9Xnd3\src\tail.jl:44 [inlined]
 [7] macro expansion at C:\Users\username\.julia\packages\MacroTools\X77lQ\src\match\macro.jl:18 [inlined]
 [8] lastcalls(::Lazy.var"#17#18"{Array{Symbol,1}}, ::Expr) at C:\Users\username\.julia\packages\Lazy\9Xnd3\src\tail.jl:7
 [9] (::Lazy.var"#13#14"{Lazy.var"#17#18"{Array{Symbol,1}}})(::Expr) at C:\Users\username\.julia\packages\Lazy\9Xnd3\src\tail.jl:22
 [10] walk(::Expr, ::Function, ::Lazy.var"#13#14"{Lazy.var"#17#18"{Array{Symbol,1}}}) at C:\Users\username\.julia\packages\MacroTools\X77lQ\src\utils.jl:105
 [11] postwalk(::Function, ::Expr) at C:\Users\username\.julia\packages\MacroTools\X77lQ\src\utils.jl:114
 [12] retcalls(::Function, ::Expr) at C:\Users\username\.julia\packages\Lazy\9Xnd3\src\tail.jl:21
 [13] tailcalls(::Function, ::Expr) at C:\Users\username\.julia\packages\Lazy\9Xnd3\src\tail.jl:26
 [14] @bounce(::LineNumberNode, ::Module, ::Any) at C:\Users\username\.julia\packages\Lazy\9Xnd3\src\tail.jl:128
 [15] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091

I suspected that it had something to do with LineNumberNode arguments within the expression, so I decided to prettify the expression in the macro definition and the problem went away:
(at src/tail.jl)

macro bounce(def)
  def = macroexpand(@__MODULE__, prettify(def))
  @assert isdef(def)
  @assert isexpr(def.args[1].args[1], Symbol) # TODO: handle f{T}() = ... 

Still not sure what happened there...

uribalb added a commit to uribalb/Lazy.jl that referenced this issue Sep 22, 2020
uribalb added a commit to uribalb/Lazy.jl that referenced this issue Sep 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant