Skip to content

Commit

Permalink
Support more forms of at-nospecialize.
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed Nov 7, 2017
1 parent 5bd5e8c commit bce0ed1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
18 changes: 15 additions & 3 deletions src/Compat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,23 @@ using Base.Meta
@static if !isdefined(Base, Symbol("@nospecialize"))
# 0.7
macro nospecialize(arg)
earg = esc(arg)
if isa(arg, Symbol)
return :($earg::ANY)
# @nospecialize(arg)
return :($(esc(arg))::ANY)
elseif isa(arg, Expr) && arg.head == :(::)
# @nospecialize(arg::typ)
arg, typ = arg.args
return :($(esc(arg))::ANY)
elseif isa(arg, Expr) && arg.head == :(=)
# @nospecialize(arg=val)
arg, val = arg.args
if isa(arg, Expr) && arg.head == :(::)
# @nospecialize(arg::typ=val)
arg, _ = arg.args
end
return Expr(:kw, :($(esc(arg))::ANY), esc(val))
end
return earg
return esc(arg)
end
export @nospecialize
end
Expand Down
7 changes: 3 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -759,10 +759,9 @@ end

# @nospecialize
# 0.7
no_specialize(@nospecialize(x)) = sin(1)
no_specialize(@nospecialize(x::Integer)) = sin(2)
@test no_specialize(1.0) == sin(1)
@test no_specialize(1) == sin(2)
no_specialize1(@nospecialize(x)) = nothing
no_specialize2(@nospecialize(x=y)) = nothing
no_specialize3(@nospecialize(x::Integer=y)) = nothing

# 0.7
@test read(IOBuffer("aaaa"), String) == "aaaa"
Expand Down

0 comments on commit bce0ed1

Please sign in to comment.