Skip to content

Cannot handle file: Nothing LineNumberNodes #701

@cstjean

Description

@cstjean

MacroTools' @q and @qq are macros that behave like quote, but @q strips out all LineInfo and @qq is "Like the quote keyword but replace construction site line numbers with __source__". I was debugging some MacroTools issue and found that this code fails:

using MacroTools: @qq, @q
using JuliaInterpreter

macro inner()
    @qq begin end
end

macro outer()
    @q @inner()
end

foo() = @outer

@interpret foo()

output:

ERROR: LoadError: MethodError: Cannot `convert` an object of type Nothing to an object of type Symbol
The function `convert` exists, but no method is defined for this combination of argument types.

Closest candidates are:
  Symbol(::Any...)
   @ Base strings/basic.jl:229
  convert(::Type{T}, ::T) where T
   @ Base Base.jl:126

Stacktrace:
  [1] setindex!(h::Dict{Symbol, Nothing}, v0::Nothing, key0::Nothing)
    @ Base ./dict.jl:346
  [2] push!(s::Set{Symbol}, x::Nothing)
    @ Base ./set.jl:137
  [3] JuliaInterpreter.FrameCode(scope::Method, src::Core.CodeInfo; generator::Bool, optimize::Bool)
    @ JuliaInterpreter ~/.julia/packages/JuliaInterpreter/nxxiG/src/types.jl:165
  [4] FrameCode
    @ ~/.julia/packages/JuliaInterpreter/nxxiG/src/types.jl:126 [inlined]
  [5] prepare_framecode(method::Method, argtypes::Any; enter_generated::Bool)
    @ JuliaInterpreter ~/.julia/packages/JuliaInterpreter/nxxiG/src/construct.jl:170
  [6] prepare_framecode
    @ ~/.julia/packages/JuliaInterpreter/nxxiG/src/construct.jl:130 [inlined]
  [7] prepare_call(f::Any, allargs::Vector{Any}; enter_generated::Bool)
    @ JuliaInterpreter ~/.julia/packages/JuliaInterpreter/nxxiG/src/construct.jl:250
  [8] prepare_call
    @ ~/.julia/packages/JuliaInterpreter/nxxiG/src/construct.jl:227 [inlined]
  [9] determine_method_for_expr(expr::Expr; enter_generated::Bool)
    @ JuliaInterpreter ~/.julia/packages/JuliaInterpreter/nxxiG/src/construct.jl:586
 [10] determine_method_for_expr
    @ ~/.julia/packages/JuliaInterpreter/nxxiG/src/construct.jl:577 [inlined]
 [11] enter_call_expr(expr::Expr; enter_generated::Bool)
    @ JuliaInterpreter ~/.julia/packages/JuliaInterpreter/nxxiG/src/construct.jl:625
 [12] enter_call_expr(expr::Expr)
    @ JuliaInterpreter ~/.julia/packages/JuliaInterpreter/nxxiG/src/construct.jl:623
 [13] top-level scope
    @ ~/Programa/scratch.jl:753
 [14] include(fname::String)
    @ Main ./sysimg.jl:38
 [15] top-level scope
    @ REPL[2]:1
in expression starting at /Users/cedric/Programa/scratch.jl:14

The reason for failure is quite simply that the file is nothing

julia> dump(@macroexpand @outer)
Expr
  head: Symbol block
  args: Array{Any}((1,))
    1: LineNumberNode
      line: Int64 0
      file: Nothing nothing

while the FrameCode constructor assumes that file is a Symbol, hence the MethodError. It'd be quite easy to fix with a lt.file === nothing && continue PR. Shall I do that? I could also fix MacroTools (I wrote the @qq macro) if someone makes the case that MacroTools' output is wrong.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions