Skip to content

Commit

Permalink
fix #30792, static param constraints between positional and kw args (#…
Browse files Browse the repository at this point in the history
…30798)

(cherry picked from commit 4b74158)
  • Loading branch information
JeffBezanson authored and KristofferC committed Feb 11, 2019
1 parent d309c4b commit 8d8b0f2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
16 changes: 5 additions & 11 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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]...)
Expand All @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions test/keywordargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8d8b0f2

Please sign in to comment.