Skip to content

Commit

Permalink
fix #38501, wrap interpolated literal strings in :string exprs (#38692
Browse files Browse the repository at this point in the history
)
  • Loading branch information
JeffBezanson authored Dec 4, 2020
1 parent b78e505 commit 88f445a
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/julia-parser.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2263,7 +2263,10 @@
(loop (read-char p) b e 0))))

((and (eqv? c #\$) (not raw))
(let ((ex (parse-interpolate s)))
(let* ((ex (parse-interpolate s))
;; wrap interpolated literal strings in (string ) so we can
;; distinguish them from the surrounding text (issue #38501)
(ex (if (string? ex) `(string ,ex) ex)))
(loop (read-char p)
(open-output-string)
(list* ex (io.tostring! b) e)
Expand Down
8 changes: 7 additions & 1 deletion src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2308,7 +2308,13 @@
'bracescat (lambda (e) (error "{ } matrix syntax is discontinued"))

'string
(lambda (e) (expand-forms `(call (top string) ,@(cdr e))))
(lambda (e)
(expand-forms
`(call (top string) ,@(map (lambda (s)
(if (and (pair? s) (eq? (car s) 'string))
(cadr s)
s))
(cdr e)))))

'|::|
(lambda (e)
Expand Down
2 changes: 2 additions & 0 deletions test/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ end
@test_repr ":(:(:(x)))"
@test_repr "-\"\""
@test_repr "-(<=)"
@test_repr "\$x"
@test_repr "\$(\"x\")"

# order of operations
@test_repr "x + y * z"
Expand Down
3 changes: 3 additions & 0 deletions test/syntax.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2642,3 +2642,6 @@ end
@test ncalls_in_lowered(quote a, _... = b, c end, GlobalRef(Base, :rest)) == 0
@test ncalls_in_lowered(quote a, _... = (b...,) end, GlobalRef(Base, :rest)) == 0
end

# issue #38501
@test :"a $b $("str") c" == Expr(:string, "a ", :b, " ", Expr(:string, "str"), " c")

0 comments on commit 88f445a

Please sign in to comment.