-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Closed
Labels
bugIndicates an unexpected problem or unintended behaviorIndicates an unexpected problem or unintended behaviortypes and dispatchTypes, subtyping and method dispatchTypes, subtyping and method dispatch
Description
On julia v1.5.0-rc1
I'm trying to define a bunch of methods using metaprogramming and I'm seeing a stack overflow error upon call to eval.
The following code manages to define the first method in the loop, but while evaling the second one the error is thrown
struct MyType{T,N}
x::T
end
f(x::MyType) = x.x
f(x) = x
for XT in (:T, Symbol("MyType{T,N}")), YT in (:T, Symbol("MyType{T,N}")), ZT in (:T, Symbol("MyType{T,N}"))
XT == YT == ZT == :T && continue
ex = """
function Base.muladd(x::$XT,y::$YT,z::$ZT) where {T,N}
res = muladd(f(x),f(y),f(z))
MyType{eltype(res),N}(res)
end
"""
println(ex)
eval(Meta.parse(ex))
endThe reason I'm parsing a string and not building the expression directly is that I couldn't figure out how to interpolate Symbol("MyType{T,N}") into the expression, it just produced z::var"MyType{T,N}" instead of z::MyType{T,N}.
The output of the program (notice the print statement printing the expression) is
function Base.muladd(x::T,y::T,z::MyType{T,N}) where {T,N}
res = muladd(f(x),f(y),f(z))
MyType{eltype(res),N}(res)
end
function Base.muladd(x::T,y::MyType{T,N},z::T) where {T,N}
res = muladd(f(x),f(y),f(z))
MyType{eltype(res),N}(res)
end
ERROR: StackOverflowError:
Stacktrace:
[1] top-level scope at none:1
[2] eval at ./boot.jl:331 [inlined]
[3] eval(::Expr) at ./client.jl:467
[4] top-level scope at ./none:10Metadata
Metadata
Assignees
Labels
bugIndicates an unexpected problem or unintended behaviorIndicates an unexpected problem or unintended behaviortypes and dispatchTypes, subtyping and method dispatchTypes, subtyping and method dispatch