This looks to be a known issue (2586). The entire expression is sent to the
compiler as a single "thunk" because of the `ccall`, but type declarations
can only be evaluated at global scope. You would see the same error when
trying to evaluate the resulting quoted expression, so this is not unique
to the macro. I'm not sure if there is a work-around for macro-generated
code at the moment.

Aside from the error, though, the intention of this line is unclear:

typealias goox ccall((:clock,"libc"),Int32,())


(this effectively means `const goox = ccall(...)` -- which would exhibit
the same error message)


On Wed, Oct 21, 2015 at 2:34 PM, <[email protected]> wrote:

> Hi,
>
> I am having the following problem. Here is my code:
> julia> macro myname(arg)
>               typname = esc(arg)
>               privtypname = esc(symbol(string("priv",arg)))
>               code = quote
>                   typealias $(typname) ccall( (:clock, "libc"), Int32, ())
>                   type $privtypname
>                       a
>                   end
>               end
>               return code
>        end
>
> the error i get is : *ERROR: error compiling anonymous: type definition
> not allowed inside a local scope*
>
> Can anyone tell me what is wrong? The macroexpand code seems normal:
>
> julia> macroexpand(:(@myname goox))
> quote  # none, line 5:
>     typealias goox ccall((:clock,"libc"),Int32,()) # none, line 6:
>     type privgoox # none, line 7:
>         a
>     end
> end
>
> thanks
>

Reply via email to