Skip to content

Commit 0c20e64

Browse files
committed
Merge pull request #14760 from JuliaLang/ob/emptykwarg
Ignore empty parameter list while lowering
2 parents df928bd + 610ce39 commit 0c20e64

File tree

2 files changed

+44
-35
lines changed

2 files changed

+44
-35
lines changed

src/julia-syntax.scm

+41-35
Original file line numberDiff line numberDiff line change
@@ -536,45 +536,51 @@
536536
(iota (length opt)))
537537
,(method-def-expr name sparams overall-argl body isstaged))))
538538

539+
(define (remove-empty-parameters argl)
540+
(if (and (has-parameters? argl) (null? (cdar argl)))
541+
(cdr argl)
542+
argl))
543+
539544
(define (method-def-expr name sparams argl body isstaged)
540-
(if (any kwarg? argl)
541-
;; has optional positional args
542-
(begin
543-
(let check ((l argl)
544-
(seen? #f))
545-
(if (pair? l)
546-
(if (kwarg? (car l))
547-
(check (cdr l) #t)
548-
(if (and seen? (not (vararg? (car l))))
549-
(error "optional positional arguments must occur at end")
550-
(check (cdr l) #f)))))
551-
(receive
552-
(kws argl) (separate kwarg? argl)
553-
(let ((opt (map cadr kws))
554-
(dfl (map caddr kws)))
555-
(if (has-parameters? argl)
556-
;; both!
557-
;; separate into keyword version with all positional args,
558-
;; and a series of optional-positional-defs that delegate keywords
559-
(let ((kw (car argl))
560-
(argl (cdr argl)))
561-
(check-kw-args (cdr kw))
545+
(let ((argl (remove-empty-parameters argl)))
546+
(if (any kwarg? argl)
547+
;; has optional positional args
548+
(begin
549+
(let check ((l argl)
550+
(seen? #f))
551+
(if (pair? l)
552+
(if (kwarg? (car l))
553+
(check (cdr l) #t)
554+
(if (and seen? (not (vararg? (car l))))
555+
(error "optional positional arguments must occur at end")
556+
(check (cdr l) #f)))))
557+
(receive
558+
(kws argl) (separate kwarg? argl)
559+
(let ((opt (map cadr kws))
560+
(dfl (map caddr kws)))
561+
(if (has-parameters? argl)
562+
;; both!
563+
;; separate into keyword version with all positional args,
564+
;; and a series of optional-positional-defs that delegate keywords
565+
(let ((kw (car argl))
566+
(argl (cdr argl)))
567+
(check-kw-args (cdr kw))
568+
(receive
569+
(vararg req) (separate vararg? argl)
570+
(optional-positional-defs name sparams req opt dfl body isstaged
571+
(cons kw (append req opt vararg))
572+
`(parameters (... ,(gensy))))))
573+
;; optional positional only
562574
(receive
563575
(vararg req) (separate vararg? argl)
564576
(optional-positional-defs name sparams req opt dfl body isstaged
565-
(cons kw (append req opt vararg))
566-
`(parameters (... ,(gensy))))))
567-
;; optional positional only
568-
(receive
569-
(vararg req) (separate vararg? argl)
570-
(optional-positional-defs name sparams req opt dfl body isstaged
571-
(append req opt vararg)))))))
572-
(if (has-parameters? argl)
573-
;; keywords only
574-
(begin (check-kw-args (cdar argl))
575-
(keywords-method-def-expr name sparams argl body isstaged))
576-
;; neither
577-
(method-def-expr- name sparams argl body isstaged))))
577+
(append req opt vararg)))))))
578+
(if (has-parameters? argl)
579+
;; keywords only
580+
(begin (check-kw-args (cdar argl))
581+
(keywords-method-def-expr name sparams argl body isstaged))
582+
;; neither
583+
(method-def-expr- name sparams argl body isstaged)))))
578584

579585
;; remove nested blocks
580586
(define (flatten-blocks e)

test/core.jl

+3
Original file line numberDiff line numberDiff line change
@@ -3670,3 +3670,6 @@ foo9677(x::Array) = invoke(foo9677,(AbstractArray,),x)
36703670
# issue #6846
36713671
f6846() = (please6846; 2)
36723672
@test_throws UndefVarError f6846()
3673+
3674+
# issue #14758
3675+
@test isa(eval(:(f14758(; $([]...)) = ())), Function)

0 commit comments

Comments
 (0)