From ee2211c1b6a8311a900ab1fa7102775d2983eef0 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 4 May 2018 22:10:15 +0100 Subject: [PATCH] fix #26916, anon fn syntax with 1 kw and 1 optional arg (#26970) --- src/julia-parser.scm | 6 ++---- test/keywordargs.jl | 11 +++++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 88666eb109534..5629281852624 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -1969,11 +1969,9 @@ (cond ((eq? (car e) 'tuple) (map =-to-kw (cdr e))) ((eq? (car e) 'block) (cond ((length= e 1) '()) - ((length= e 2) (list (cadr e))) + ((length= e 2) (list (=-to-kw (cadr e)))) ((length= e 3) - (if (assignment? (caddr e)) - `((parameters (kw ,@(cdr (caddr e)))) ,(cadr e)) - `((parameters ,(caddr e)) ,(cadr e)))) + `((parameters ,(=-to-kw (caddr e))) ,(=-to-kw (cadr e)))) (else (error "more than one semicolon in argument list")))) (else diff --git a/test/keywordargs.jl b/test/keywordargs.jl index 20332327f6454..51c6c60e83772 100644 --- a/test/keywordargs.jl +++ b/test/keywordargs.jl @@ -320,3 +320,14 @@ end @test_throws UndefKeywordError g(1) @test_throws UndefKeywordError g(1, z=2) end + +@testset "issue #26916 - anonymous function with 1 keyword arg and 1 optional arg" begin + f = (x=1;y=2)->(x,y) + @test f() == (1,2) + @test f(10) == (10,2) + @test f(y=20) == (1,20) + @test f(20, y=30) == (20,30) + g = (x=1;)->(x,x) + @test g() == (1,1) + @test g(2) == (2,2) +end