From 8012ba1ec6e825af1efeb6e9badafa0bb0b0d698 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Thu, 29 Nov 2018 15:17:59 -0500 Subject: [PATCH] fix #29781, disallow spaces in broadcast calls (#30182) --- NEWS.md | 2 ++ src/julia-parser.scm | 3 +++ test/syntax.jl | 2 ++ 3 files changed, 7 insertions(+) diff --git a/NEWS.md b/NEWS.md index ff5285e58b5d1..fd0947d48a3b5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -11,6 +11,8 @@ Language changes * Parser inputs ending with a comma are now consistently treated as incomplete. Previously they were sometimes parsed as tuples, depending on whitespace ([#28506]). + * Spaces were accidentally allowed in broadcast call syntax, e.g. `f. (x)`. They are now + disallowed, consistent with normal function call syntax ([#29781]). * Big integer literals and command syntax (backticks) are now parsed with the name of the macro (`@int128_str`, `@uint128_str`, `@big_str`, `@cmd`) qualified to refer to the `Core` module ([#29968]). diff --git a/src/julia-parser.scm b/src/julia-parser.scm index b9f80af1b5dd7..8cd3564f7869d 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -1201,6 +1201,9 @@ (loop (cond ((eqv? (peek-token s) #\() (begin + (if (ts:space? s) + (error (string "space before \"(\" not allowed in \"" + (deparse ex) ". (\""))) (take-token s) `(|.| ,ex (tuple ,@(parse-call-arglist s #\) ))))) ((eqv? (peek-token s) ':) diff --git a/test/syntax.jl b/test/syntax.jl index 46a0be662a76a..891eeb5a21956 100644 --- a/test/syntax.jl +++ b/test/syntax.jl @@ -1328,6 +1328,8 @@ end @test Meta.parse("+((1,2))") == Expr(:call, :+, Expr(:tuple, 1, 2)) @test_throws ParseError("space before \"(\" not allowed in \"+ (\"") Meta.parse("1 -+ (a=1, b=2)") +# issue #29781 +@test_throws ParseError("space before \"(\" not allowed in \"sin. (\"") Meta.parse("sin. (1)") @test Meta.parse("1 -+(a=1, b=2)") == Expr(:call, :-, 1, Expr(:call, :+, Expr(:kw, :a, 1), Expr(:kw, :b, 2)))