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

False detection of unterminated string literal in comment #6561

Closed
vicuna opened this issue Sep 16, 2014 · 5 comments
Closed

False detection of unterminated string literal in comment #6561

vicuna opened this issue Sep 16, 2014 · 5 comments
Assignees

Comments

@vicuna
Copy link

vicuna commented Sep 16, 2014

Original bug ID: 6561
Reporter: SurfMaths
Assigned to: @gasche
Status: closed (set by @xavierleroy on 2016-12-07T10:34:43Z)
Resolution: not a bug
Priority: normal
Severity: tweak
Platform: x86_64
OS: Archlinux
OS Version: 3.16.2-1-ARCH
Version: 4.02.0+beta1 / +rc1
Category: typing
Monitored by: @gasche

Bug description

Parsing comments is a weird behavior and in this case it detect an unterminated string literal in a string-less comment (if it makes any sense...).

Discovered while compiling 'coq' v8.4pl4 (kernel/univ.ml).

If it is an expected behavior, why is it an error and not a warning?

Steps to reproduce

$ ocaml
OCaml version 4.02.0

(* between u v = {w|u<=w<=v, w canonical} *)

Error: This comment contains an unterminated string literal

@vicuna
Copy link
Author

vicuna commented Sep 16, 2014

Comment author: @yallop

Since 4.02 '{w|' begins a string literal, so the diagnostic is correct:

http://caml.inria.fr/pub/docs/manual-ocaml/extn.html#sec244

@vicuna
Copy link
Author

vicuna commented Sep 16, 2014

Comment author: @lpw25

This is not the first time this has confused people, perhaps the error message should indicate that it is a {foo| ... |foo} style literal that is unterminated.

@vicuna
Copy link
Author

vicuna commented Sep 16, 2014

Comment author: SurfMaths

As a side joke, should I expect in the future to see errors due to bad grammar, incorrect typography or insanities in comments?

Comment nesting is a useful feature, but it is false to assume that all comments are meant to contains valid code:

The following comment is also invalid:
(* Default size: 8.5" x 11" x 4" *)

@vicuna
Copy link
Author

vicuna commented Sep 16, 2014

Comment author: @alainfrisch

Comment nesting is a useful feature, but it is false to assume that all
comments are meant to contains valid code:

Indeed, but there is a currently a single syntax for comments in OCaml, and we cannot afford to break the property that it can be used to disable an arbitrary fragment of valid code.

As a matter of fact, the new syntax for string literals can be used to support comments with invalid code in them:

({| Default size: 8.5" x 11" x 4" |})

assuming that the text doesn't contain the |} fragment; otherwise, you can use:

({foo| .... |foo})

and pick foo such that the comment doesn't contain |foo}

@vicuna
Copy link
Author

vicuna commented Sep 16, 2014

Comment author: SurfMaths

Ah, I see where is the problem.

For future reference, without interpreting string literals in comments, we would have a bug if we comment the following fragment of code:

let x = "*)" in

Into

(* let x = "*)" in *)

Thanks for the explanation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants