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
Improve warning 14: illegal backslash. Fix #10929 #10931
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find the hint about quoted strings confusing, as the example has no relation with code that triggers the warning. Personally I would remove it. Otherwise the PR looks fine to me.
@@ -2,6 +2,10 @@ Line 7, characters 15-17: | |||
7 | let invalid = "\99" ;; | |||
^^ | |||
Warning 14 [illegal-backslash]: illegal backslash escape in string. | |||
Hint: Single backslashes \ are reserved for escape sequences | |||
(\n, \r...). Did you check the list of OCaml escape sequences? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(\n, \r...). Did you check the list of OCaml escape sequences? | |
(\n, \r, ...). Did you check the list of OCaml escape sequences? |
If I am not mistaken, @dra27 's idea for quoted strings was : if there is no valid escape sequence in the raw string, propose to use quoted strings with the raw string: let test = "av\*" would trigger
but not for example like let ambiguous = "a\n\*" |
You're right, I misunderstood @dra27's idea. The mechanism for adding logic that depends on the string that raised the warning is less clear to me, so it would take me more time to make a full PR. In that case, would it be alright to split that into two PRs? The first would be this one, with the typo corrected and the mention of quoted strings removed. The second one would have the logic for suggesting quoted strings when no valid escape sequence is found in the raw string. |
Personally I find the hint for quoted strings a bit too clever and would be fine without it, but I am not strongly opposed either. |
It is perfectly fine to split the potentially too clever quoted strings hint into another (potential) PR. |
a4f692d
to
cf72f0b
Compare
utils/warnings.ml
Outdated
| Illegal_backslash -> | ||
"illegal backslash escape in string.\n\ | ||
Hint: Single backslashes \\ are reserved for escape sequences\n\ | ||
(\\n, \\r...). Did you check the list of OCaml escape sequences?\n\ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nojb's change needs to be here (then in the reference files as well)
(\\n, \\r...). Did you check the list of OCaml escape sequences?\n\ | |
(\\n, \\r, ...). Did you check the list of OCaml escape sequences?\n\ |
@Octachron is (of course!) correct about what I was trying to get at. The rationale for suggesting it is that it's useful when accidentally generating things like |
When I play videogames, loading screens include random hints. What's the OCaml compiler equivalent of that? I guess we could ask editor modes to show a "Did you know: ..." banner once every day. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM (modulo the missing space)
@@ -3,9 +3,8 @@ Line 7, characters 15-17: | |||
^^ | |||
Warning 14 [illegal-backslash]: illegal backslash escape in string. | |||
Hint: Single backslashes \ are reserved for escape sequences | |||
(\n, \r...). Did you check the list of OCaml escape sequences? | |||
(\n, \r,...). Did you check the list of OCaml escape sequences? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(\n, \r,...). Did you check the list of OCaml escape sequences? | |
(\n, \r, ...). Did you check the list of OCaml escape sequences? |
Sorry for the activity, I had some struggles with git. I like the idea of suggestions and hints too. In other languages, this tends to be in linters, but I'm not aware of any linter for OCaml. |
An important notice @lucas-deangelis: we are still sorting out the repository state after the multicore merge. The merge of non- |
Fix typo, update reviewers list.
Thank you for the notice. I've fixed the typo and completed the reviewers list. |
@lucas-deangelis , we are once again merging non-multicore PRs for OCaml. If you have the time to rebase your PR (to fix the Changes entry), it can now be merged. |
Adds a few explanations on why this warning may occur, and a few hints on how to fix it.
I have updated the Changes entry for the PR, and I am planning to merge it tomorrow if there are no objections. |
I was about to do the same, so, yeah. |
A pretty frequent mistake among OCaml beginners that I've seen is writing |
Reading the error message in the test suite, I did think that we could go one step further and recognize that either |
There's already some discussion in the linked issue, #10929. All tests pass locally,
check-typo
doesn't report any issue.