Skip to content

Interpolation of signature into function...end Expr causes syntax error if there is a function body #25080

@jrevels

Description

@jrevels

I thought an issue existed for something like this already, but I couldn't find it...apologies if it's a duplicate.

julia> signature = :(f(x))
:(f(x))

# works fine without body
julia> quote
           function $signature
           end
       end
quote
    #= REPL[3]:2 =#
    function f(x) end
end

# adding a body causes a syntax error
julia> quote
           function $signature
               1
           end
       end
ERROR: syntax: expected "end" in definition of function "($ signature)"

Luckily, there's an easy workaround:

julia> quote
           $signature = begin
               return 1
           end
       end
quote
    #= REPL[4]:2 =#
    f(x) = begin
            #= REPL[4]:3 =#
            return 1
        end
en
julia> versioninfo()
Julia Version 0.7.0-DEV.2826
Commit 66b2090 (2017-12-11 19:50 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin16.7.0)
  CPU: Intel(R) Core(TM) i5-4288U CPU @ 2.60GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Haswell)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, haswell)
Environment:

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