From 610ce39fc541cfbc927b9507d17a5c7de321bc5a Mon Sep 17 00:00:00 2001 From: Oscar Blumberg Date: Thu, 21 Jan 2016 18:46:28 -0500 Subject: [PATCH] Ignore empty parameter list while lowering Fix #14758. --- src/julia-syntax.scm | 76 ++++++++++++++++++++++++-------------------- test/core.jl | 3 ++ 2 files changed, 44 insertions(+), 35 deletions(-) diff --git a/src/julia-syntax.scm b/src/julia-syntax.scm index 9287ed6ea8fc0..345920e46b247 100644 --- a/src/julia-syntax.scm +++ b/src/julia-syntax.scm @@ -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) diff --git a/test/core.jl b/test/core.jl index 68d393efcd885..f3d48951c8be1 100644 --- a/test/core.jl +++ b/test/core.jl @@ -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)