Skip to content

Commit

Permalink
fix other part of #21147, optional instead of keyword args
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Mar 25, 2017
1 parent cc379ae commit f177e82
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -469,16 +469,7 @@
,(method-def-expr-
name
;; remove sparams that don't occur, to avoid printing the warning twice
(let loop ((filtered '())
(params positional-sparams))
(cond ((null? params)
(reverse! filtered))
((or (expr-contains-eq (caar params) (cons 'list argl))
(any (lambda (v) (expr-contains-eq (caar params) v))
(cdr params)))
(loop (cons (car params) filtered) (cdr params)))
(else
(loop filtered (cdr params)))))
(filter-sparams (cons 'list argl) 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 Expand Up @@ -564,16 +555,26 @@
(cdr body))
'()))

;; keep only sparams used by `expr` or other sparams
(define (filter-sparams expr sparams)
(let loop ((filtered '())
(params sparams))
(cond ((null? params)
(reverse! filtered))
((or (expr-contains-eq (caar params) expr)
(any (lambda (v) (expr-contains-eq (caar params) v))
(cdr params)))
(loop (cons (car params) filtered) (cdr params)))
(else
(loop filtered (cdr params))))))

(define (optional-positional-defs name sparams req opt dfl body isstaged overall-argl rett)
(let ((prologue (extract-method-prologue body)))
`(block
,@(map (lambda (n)
(let* ((passed (append req (list-head opt n)))
;; only keep static parameters used by these arguments
(sp (filter (lambda (sp)
(contains (lambda (e) (eq? e (car sp)))
passed))
sparams))
(sp (filter-sparams (cons 'list passed) sparams))
(vals (list-tail dfl n))
(absent (list-tail opt n)) ;; absent arguments
(body
Expand Down
5 changes: 5 additions & 0 deletions test/keywordargs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,3 +265,8 @@ function f21147(f::Tuple{A}; kwargs...) where {B,A<:Tuple{B}}
end
@test f21147(((1,),)) === Int
@test f21147(((1,),), k = 2) === Int
function g21147(f::Tuple{A}, k = 2) where {B,A<:Tuple{B}}
return B
end
@test g21147(((1,),)) === Int
@test g21147(((1,),), 2) === Int

0 comments on commit f177e82

Please sign in to comment.