From 169daa43b80a8c65550c5cde1d6fd1eb7c201cfe Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Wed, 10 May 2017 16:50:10 -0400 Subject: [PATCH] fix #20575, syntax error for juxtaposing a string literal --- NEWS.md | 2 ++ src/julia-parser.scm | 4 +++- test/parse.jl | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 27dc6ad493e44..c1dcc42c82090 100644 --- a/NEWS.md +++ b/NEWS.md @@ -17,6 +17,8 @@ This section lists changes that do not have deprecation warnings. * `ntuple(f, n::Integer)` throws `ArgumentError` if `n` is negative. Previously an empty tuple was returned ([#21697]). + * Juxtaposing string literals (e.g. `"x"y`) is now a syntax error ([#20575]). + * `@__DIR__` returns the current working directory rather than `nothing` when not run from a file ([#21759]). diff --git a/src/julia-parser.scm b/src/julia-parser.scm index a3806d96217bb..54c854be6b58f 100644 --- a/src/julia-parser.scm +++ b/src/julia-parser.scm @@ -876,9 +876,11 @@ ) (not (ts:space? s)) (not (operator? t)) - (not (initial-reserved-word? t)) (not (closing-token? t)) (not (newline? t)) + (or (not (string? expr)) ;; issue #20575 + (error "cannot juxtapose string literal")) + (not (initial-reserved-word? t)) (not (and (pair? expr) (syntactic-unary-op? (car expr)))) ;; TODO: this would disallow juxtaposition with 0, which is ambiguous ;; with e.g. hex literals `0x...`. however this is used for `0im`, which diff --git a/test/parse.jl b/test/parse.jl index df2f38cfbd36f..858393df4ee98 100644 --- a/test/parse.jl +++ b/test/parse.jl @@ -1149,6 +1149,10 @@ f21586(; @m21586(a), @m21586(b)) = a + b end @test Test21604.X(1.0) === Test21604.X(1.0) +# issue #20575 +@test_throws ParseError parse("\"a\"x") +@test_throws ParseError parse("\"a\"begin end") + # comment 298107224 on pull #21607 module Test21607 using Base.Test