"error: unclosed comment" in multiline comments

While converting a template from Java to Scala, I noticed the following quirk with multi-line comments, which can be boiled down to the following snippet:

/**
 * /*
 */

class Blah {}

      

The above will not compile with "error: unclosed comment" being valid in Java.

This turns out to be problematic as it makes it difficult to document, for example. accepting globe strings (eg "requires a path such as something/*.myformat

").

Is this a bug or a feature?

+3


source to share


1 answer


This is essentially a function . To quote Section 1.4 of the Scala Language Specification :

A multi-line comment is a sequence of characters between /*

and */

. Multiline comments can be nested, but must be correct nested. Therefore, the comment /* /* */

will seem to be rejected as having an unterminated comment.

(emph my)



Fortunately, it is relatively easy to work around if you need it (like the glob example from the question) by escaping /

or *

literal
, netting something like:

/**
 * /*
 */

      

which displays correctly in the generated Scaladoc.

+6


source







All Articles