From 007faad6417fd368eb874e9403200bc6720142d2 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Tue, 22 Jan 2019 13:19:11 -0500 Subject: [PATCH] fix #30792, static param constraints between positional and kw args --- src/julia-syntax.scm | 16 +++++----------- test/keywordargs.jl | 11 +++++++++++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 632f75927f2ef..8c4232e484607 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -394,6 +394,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 @@ -422,13 +424,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))) @@ -460,7 +456,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]...) @@ -476,9 +472,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