Skip to content

Commit

Permalink
Merge pull request #14760 from JuliaLang/ob/emptykwarg
Browse files Browse the repository at this point in the history
Ignore empty parameter list while lowering
  • Loading branch information
carnaval committed Jan 22, 2016
2 parents df928bd + 610ce39 commit 0c20e64
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 35 deletions.
76 changes: 41 additions & 35 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -536,45 +536,51 @@
(iota (length opt)))
,(method-def-expr name sparams overall-argl body isstaged))))

(define (remove-empty-parameters argl)
(if (and (has-parameters? argl) (null? (cdar argl)))
(cdr argl)
argl))

(define (method-def-expr name sparams argl body isstaged)
(if (any kwarg? argl)
;; has optional positional args
(begin
(let check ((l argl)
(seen? #f))
(if (pair? l)
(if (kwarg? (car l))
(check (cdr l) #t)
(if (and seen? (not (vararg? (car l))))
(error "optional positional arguments must occur at end")
(check (cdr l) #f)))))
(receive
(kws argl) (separate kwarg? argl)
(let ((opt (map cadr kws))
(dfl (map caddr kws)))
(if (has-parameters? argl)
;; both!
;; separate into keyword version with all positional args,
;; and a series of optional-positional-defs that delegate keywords
(let ((kw (car argl))
(argl (cdr argl)))
(check-kw-args (cdr kw))
(let ((argl (remove-empty-parameters argl)))
(if (any kwarg? argl)
;; has optional positional args
(begin
(let check ((l argl)
(seen? #f))
(if (pair? l)
(if (kwarg? (car l))
(check (cdr l) #t)
(if (and seen? (not (vararg? (car l))))
(error "optional positional arguments must occur at end")
(check (cdr l) #f)))))
(receive
(kws argl) (separate kwarg? argl)
(let ((opt (map cadr kws))
(dfl (map caddr kws)))
(if (has-parameters? argl)
;; both!
;; separate into keyword version with all positional args,
;; and a series of optional-positional-defs that delegate keywords
(let ((kw (car argl))
(argl (cdr argl)))
(check-kw-args (cdr kw))
(receive
(vararg req) (separate vararg? argl)
(optional-positional-defs name sparams req opt dfl body isstaged
(cons kw (append req opt vararg))
`(parameters (... ,(gensy))))))
;; optional positional only
(receive
(vararg req) (separate vararg? argl)
(optional-positional-defs name sparams req opt dfl body isstaged
(cons kw (append req opt vararg))
`(parameters (... ,(gensy))))))
;; optional positional only
(receive
(vararg req) (separate vararg? argl)
(optional-positional-defs name sparams req opt dfl body isstaged
(append req opt vararg)))))))
(if (has-parameters? argl)
;; keywords only
(begin (check-kw-args (cdar argl))
(keywords-method-def-expr name sparams argl body isstaged))
;; neither
(method-def-expr- name sparams argl body isstaged))))
(append req opt vararg)))))))
(if (has-parameters? argl)
;; keywords only
(begin (check-kw-args (cdar argl))
(keywords-method-def-expr name sparams argl body isstaged))
;; neither
(method-def-expr- name sparams argl body isstaged)))))

;; remove nested blocks
(define (flatten-blocks e)
Expand Down
3 changes: 3 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3670,3 +3670,6 @@ foo9677(x::Array) = invoke(foo9677,(AbstractArray,),x)
# issue #6846
f6846() = (please6846; 2)
@test_throws UndefVarError f6846()

# issue #14758
@test isa(eval(:(f14758(; $([]...)) = ())), Function)

0 comments on commit 0c20e64

Please sign in to comment.