Skip to content

Commit b7d6be0

Browse files
authored
Merge pull request #21787 from JuliaLang/jb/fix20575
fix #20575, syntax error for juxtaposing a string literal
2 parents 64a230b + 169daa4 commit b7d6be0

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ This section lists changes that do not have deprecation warnings.
1717
* `ntuple(f, n::Integer)` throws `ArgumentError` if `n` is negative.
1818
Previously an empty tuple was returned ([#21697]).
1919

20+
* Juxtaposing string literals (e.g. `"x"y`) is now a syntax error ([#20575]).
21+
2022
* `@__DIR__` returns the current working directory rather than `nothing` when not run
2123
from a file ([#21759]).
2224

src/julia-parser.scm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -876,9 +876,11 @@
876876
)
877877
(not (ts:space? s))
878878
(not (operator? t))
879-
(not (initial-reserved-word? t))
880879
(not (closing-token? t))
881880
(not (newline? t))
881+
(or (not (string? expr)) ;; issue #20575
882+
(error "cannot juxtapose string literal"))
883+
(not (initial-reserved-word? t))
882884
(not (and (pair? expr) (syntactic-unary-op? (car expr))))
883885
;; TODO: this would disallow juxtaposition with 0, which is ambiguous
884886
;; with e.g. hex literals `0x...`. however this is used for `0im`, which

test/parse.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,10 @@ f21586(; @m21586(a), @m21586(b)) = a + b
11491149
end
11501150
@test Test21604.X(1.0) === Test21604.X(1.0)
11511151

1152+
# issue #20575
1153+
@test_throws ParseError parse("\"a\"x")
1154+
@test_throws ParseError parse("\"a\"begin end")
1155+
11521156
# comment 298107224 on pull #21607
11531157
module Test21607
11541158
using Base.Test

0 commit comments

Comments
 (0)