diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 7b1a15c559103..ce00f3b7cdb7f 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -396,6 +396,8 @@ (vararg (let ((l (if (null? pargl) '() (last pargl)))) (if (or (vararg? l) (varargexpr? l)) (list l) '()))) + ;; positional args with vararg + (pargl-all pargl) ;; positional args without vararg (pargl (if (null? vararg) pargl (butlast pargl))) ;; positional args with everything required; for use by the core function @@ -424,13 +426,7 @@ (filter nospecialize-meta? kargl))) ;; body statements (stmts (cdr body)) - (positional-sparams - (filter (lambda (s) - (let ((name (car s))) - (or (expr-contains-eq name (cons 'list pargl)) - (and (pair? vararg) (expr-contains-eq name (car vararg))) - (not (expr-contains-eq name (cons 'list kargl)))))) - sparams)) + (positional-sparams (filter-sparams (cons 'list pargl-all) sparams)) (keyword-sparams (filter (lambda (s) (not (any (lambda (p) (eq? (car p) (car s))) @@ -462,7 +458,7 @@ ;; call with no keyword args ,(method-def-expr- - name positional-sparams (append pargl vararg) + name positional-sparams pargl-all `(block ,@(without-generated prologue) ,(let (;; call mangled(vals..., [rest_kw,] pargs..., [vararg]...) @@ -478,9 +474,7 @@ ;; call with unsorted keyword args. this sorts and re-dispatches. ,(method-def-expr- - name - ;; remove sparams that don't occur, to avoid printing the warning twice - (filter-sparams (cons 'list argl) positional-sparams) + name positional-sparams `((|::| ;; if there are optional positional args, we need to be able to reference the function name ,(if (any kwarg? pargl) (gensy) UNUSED) diff --git a/test/keywordargs.jl b/test/keywordargs.jl index 51c6c60e83772..eacacdc2ea248 100644 --- a/test/keywordargs.jl +++ b/test/keywordargs.jl @@ -117,6 +117,17 @@ end @test kwf7(1.5;k=2.5) === Float64 @test_throws MethodError kwf7(1.5) @test_throws TypeError kwf7(1.5; k=2) + + # issue #30792 + g30792(a::C; b=R(1)) where {R <: Real, C <: Union{R, Complex{R}}} = R + @test g30792(1.0) === Float64 + @test g30792(1.0im) === Float64 + @test g30792(1.0im, b=1) === Float64 + @test_throws MethodError g30792("") + f30792(a::C; b::R=R(1)) where {R <: Real, C <: Union{R, Complex{R}}} = R + @test f30792(2im) === Int + @test f30792(2im, b=3) === Int + @test_throws TypeError f30792(2im, b=3.0) end # try to confuse it with quoted symbol kwf8(x::MIME{:T};k::T=0) where {T} = 0