Skip to content

Commit b28bb24

Browse files
0x005cJeffBezanson
authored andcommitted
Improve error message for character literal (#34435)
1 parent 159de94 commit b28bb24

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

src/julia-parser.scm

+6-3
Original file line numberDiff line numberDiff line change
@@ -2264,9 +2264,12 @@
22642264
b))
22652265
(loop (read-char (ts:port s))))))
22662266
(let ((str (tostr #f b)))
2267-
(if (= (string-length str) 1)
2268-
(string.char str 0)
2269-
(error "invalid character literal")))))))
2267+
(let ((len (string-length str)))
2268+
(if (= len 1)
2269+
(string.char str 0)
2270+
(if (= len 0)
2271+
(error "invalid empty character literal")
2272+
(error "character literal contains multiple characters")))))))))
22702273

22712274
;; symbol/expression quote
22722275
((eq? t ':)

test/syntax.jl

+6
Original file line numberDiff line numberDiff line change
@@ -1994,3 +1994,9 @@ end
19941994
end
19951995
pop = 1
19961996
end == 1
1997+
1998+
# issue #29982
1999+
@test Meta.parse("'a'") == 'a'
2000+
@test Meta.parse("'\U0061'") == 'a'
2001+
test_parseerror("''", "invalid empty character literal")
2002+
test_parseerror("'abc'", "character literal contains multiple characters")

0 commit comments

Comments
 (0)