Skip to content
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

add @callsuper macro #18252

Closed
StefanKarpinski opened this issue Aug 26, 2016 · 4 comments
Closed

add @callsuper macro #18252

StefanKarpinski opened this issue Aug 26, 2016 · 4 comments
Labels
design Design of APIs or of the language itself help wanted Indicates that a maintainer wants help on an issue or pull request speculative Whether the change will be implemented is speculative

Comments

@StefanKarpinski
Copy link
Member

As per #13123, we could add a @supercall macro that sweetens the interface to invoke and makes it more intuitive. My current implementation:

macro callsuper(ex)
    ex.head == :call || error("@invoke requires a call expression")
    args = ex.args[2:end]
    types = Symbol[]
    vals = Symbol[]
    blk = quote end
    for arg in args
            val = gensym()
            typ = gensym()
            push!(vals, val)
            push!(types, typ)
            if isa(arg,Expr) && arg.head == :(::) && length(arg.args) == 2
                push!(blk.args, :($typ = $(esc(arg.args[2]))))
                push!(blk.args, :($val = $(esc(arg.args[1]))::$typ))
            else
                push!(blk.args, :($val = $(esc(arg))))
                push!(blk.args, :($typ = typeof($val)))
            end
    end
    push!(blk.args, :(invoke($(esc(ex.args[1])), ($(types...),), $(vals...))))
    return blk
end

Support for keyword arguments could be taken from #11165.

@StefanKarpinski StefanKarpinski added speculative Whether the change will be implemented is speculative design Design of APIs or of the language itself labels Aug 26, 2016
@StefanKarpinski StefanKarpinski added this to the 0.6.0 milestone Aug 26, 2016
@StefanKarpinski StefanKarpinski added the help wanted Indicates that a maintainer wants help on an issue or pull request label Aug 26, 2016
@tkelman
Copy link
Contributor

tkelman commented Aug 26, 2016

do the types used in invoke actually have to be supertypes of the values provided?

@stevengj
Copy link
Member

stevengj commented Aug 26, 2016

Or maybe @invoke foo(x, y::T) could turn into invoke(foo, (typeof(x), T), x,y), i.e. you could use typeasserts to indicate the desired call signature.

@JeffBezanson JeffBezanson modified the milestones: 1.0, 0.6.0 Oct 17, 2016
simonbyrne added a commit that referenced this issue Jan 19, 2017
simonbyrne added a commit that referenced this issue Jan 19, 2017
@JeffBezanson JeffBezanson modified the milestones: 2.0+, 1.0 Jul 13, 2017
@JeffBezanson
Copy link
Member

As a new feature, can be considered post-1.0. Triage also feels it's unlikely we'll remove invoke for 1.0.

@StefanKarpinski StefanKarpinski modified the milestones: 2.0, 1.x Jan 22, 2019
@Keno
Copy link
Member

Keno commented Dec 25, 2020

#38438

@Keno Keno closed this as completed Dec 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
design Design of APIs or of the language itself help wanted Indicates that a maintainer wants help on an issue or pull request speculative Whether the change will be implemented is speculative
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants