4

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?

mikołak
  • 9,605
  • 1
  • 48
  • 70

1 Answers1

7

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.

Community
  • 1
  • 1
mikołak
  • 9,605
  • 1
  • 48
  • 70