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

fix #30792, static param constraints between positional and kw args #30798

Merged
merged 1 commit into from
Jan 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)))
Expand Down Expand Up @@ -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]...)
Expand All @@ -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)
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