From dc2befcffc7412768097c2a2a6819724a4745aeb Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 18 Jun 2021 14:18:45 -0400 Subject: [PATCH] fix #41253, parse error in `function (::T{})` (#41259) --- src/julia-parser.scm | 7 +++++-- test/syntax.jl | 3 +++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/julia-parser.scm b/src/julia-parser.scm index 70912c4272c8c..3a5dfad9293bd 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -1329,7 +1329,8 @@ (define (valid-1arg-func-sig? sig) (or (symbol? sig) (and (pair? sig) (eq? (car sig) '|::|) - (symbol? (cadr sig))))) + (or (symbol? (cadr sig)) + (length= sig 2))))) (define (unwrap-where x) (if (and (pair? x) (eq? (car x) 'where)) @@ -1469,7 +1470,9 @@ ;; function foo => syntax error (error (string "expected \"(\" in " word " definition"))) (if (not (valid-func-sig? paren sig)) - (error (string "expected \"(\" in " word " definition")) + (if paren + (error (string "ambiguous signature in " word " definition. Try adding a comma if this is a 1-argument anonymous function.")) + (error (string "expected \"(\" in " word " definition"))) sig))) (body (parse-block s))) (expect-end s word) diff --git a/test/syntax.jl b/test/syntax.jl index 7cee3c0755f65..6e3ec82ca3e81 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -2927,3 +2927,6 @@ b'` == `$("a\\\nb")` \\ ``` == `'\'` end + +# issue #41253 +@test (function (::Dict{}); end)(Dict()) === nothing