Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display a clear error on empty character literals '' #10197

Merged
merged 1 commit into from
Feb 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ Working version
the source code than the point explicitly shown in the error message.
(François Pottier, review by Gabriel Scherer and Frédéric Bour.)

- #10196, #10197: better error message on empty character literals ''.
(Gabriel Scherer, review by David Allsopp and Florian Angeletti
and Daniel Bünzli, report by Robin Björklin)

### Internal/compiler-libs changes:

- #9650, #9651: keep refactoring the pattern-matching compiler
Expand Down
1 change: 1 addition & 0 deletions parsing/lexer.mli
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type error =
| Unterminated_comment of Location.t
| Unterminated_string
| Unterminated_string_in_comment of Location.t * Location.t
| Empty_character_literal
| Keyword_as_label of string
| Invalid_literal of string
| Invalid_directive of string * string option
Expand Down
9 changes: 9 additions & 0 deletions parsing/lexer.mll
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type error =
| Unterminated_comment of Location.t
| Unterminated_string
| Unterminated_string_in_comment of Location.t * Location.t
| Empty_character_literal
| Keyword_as_label of string
| Invalid_literal of string
| Invalid_directive of string * string option
Expand Down Expand Up @@ -300,6 +301,12 @@ let prepare_error loc = function
Location.errorf ~loc
"This comment contains an unterminated string literal"
~sub:[Location.msg ~loc:literal_loc "String literal begins here"]
| Empty_character_literal ->
let msg = "Illegal empty character literal ''" in
let sub =
[Location.msg
"Hint: Did you mean ' ' or a type variable 'a?"] in
Location.error ~loc ~sub msg
| Keyword_as_label kwd ->
Location.errorf ~loc
"`%s' is a keyword, it cannot be used as label name" kwd
Expand Down Expand Up @@ -459,6 +466,8 @@ rule token = parse
{ CHAR(char_for_hexadecimal_code lexbuf 3) }
| "\'" ("\\" _ as esc)
{ error lexbuf (Illegal_escape (esc, None)) }
| "\'\'"
{ error lexbuf Empty_character_literal }
| "(*"
{ let s, loc = wrap_comment_lexer comment lexbuf in
COMMENT (s, loc) }
Expand Down