-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Can't do type creation inside macro when templating is used #9312
Comments
Which julia version are you using? On |
This is a bug in 0.4 I think Sent from my iPhone
|
Not yet sure why this changed. See also #2586. |
@dlfivefifty here is a (possible) work-around: macro foo(Typ,Abs)
return esc(quote
abstract $Abs{T}
immutable $Typ{S} <: $Abs{S} end
end
)
end Since @JeffBezanson seems to be on right now -- if you see this, can you comment on whether this is more than a dupe of #2586 (and #4893)? I looked at the lowering for Sheehan's examples as well as the code below (which works): julia> macro foo(AbsSup)
esc(quote abstract $AbsSup{T} end)
end
julia> @foo(Sup)
julia> macro bar(AbsSub,AbsSup)
esc(quote immutable $AbsSub{T} <: $AbsSup{T} end end)
end
julia> @bar(Sub, Sup) [edit - copied from the wrong REPL] From what I can tell the difference is that there is a lambda capture in Sheehan's example, and I believe what is happening is that |
That seems to fix the toy example, thanks! I can't test the real example in 0.4 because the code is also hit by #9378 |
Probably related (the "local T declare twice" error) try
@eval begin
abstract A1{T}
abstract B1{T} <: A1{T}
end
catch e
println(e)
end
abstract A2{T}
abstract B2{T} <: A2{T}
try
@eval begin
abstract A3{T}
type B3{T} <: A3{T}
end
end
catch e
println(e)
end
abstract A4{T}
type B4{T} <: A4{T}
end Output ErrorException("syntax: local \"T\" declared twice")
ErrorException("error compiling anonymous: type definition not allowed inside a local scope") |
Just tried this and it seems to be fixed. |
The following throws the error "ERROR: error compiling anonymous: type definition not allowed inside a local scope":
The following without the templated abstract type doesn't throw an error:
[@ivarne- edited to add quoting]
The text was updated successfully, but these errors were encountered: