Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"error: unclosed comment" in multiline comments

Tags:

scala

When converting a template from Java to Scala, I've noticed the following quirk with multiline comments that can be reduced to the following snippet:

/**
 * /*
 */

class Blah {}

The above fails to compile with "error: unclosed comment", while being valid in Java.

This proves problematic, since it makes it harder to document e.g. acceptance of glob-type strings (e.g. "requires a path like something/*.myformat").

Is this a bug or a feature?

like image 597
mikołak Avatar asked Nov 01 '25 15:11

mikołak


1 Answers

It is, in fact, a feature. To quote Section 1.4 of the Scala Language Specification:

A multi-line comment is a sequence of characters between /* and */. Multi-line comments may be nested, but are required to be properly nested. Therefore, a comment like /* /* */ will be rejected as having an unterminated comment.

(emph. mine)

Fortunately, it's relatively easy to work around in the case you need it (like the glob example from the question) by escaping the / or * literal, netting something like:

/**
 * /*
 */

which displays correctly in the generated Scaladoc.

like image 135
mikołak Avatar answered Nov 04 '25 11:11

mikołak