Skip to content

Scala 3 reporter and REPL do not respect message divider #14233

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

Closed
som-snytt opened this issue Jan 9, 2022 · 4 comments
Closed

Scala 3 reporter and REPL do not respect message divider #14233

som-snytt opened this issue Jan 9, 2022 · 4 comments
Labels
area:repl area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug Spree Suitable for a future Spree

Comments

@som-snytt
Copy link
Contributor

Compiler version

3.1 as shown

Minimized code

  scalac -d /tmp postly.scala
postly.scala:3: error: postfix operator toString needs to be enabled
by making the implicit value scala.language.postfixOps visible.
This can be achieved by adding the import clause 'import scala.language.postfixOps'
or by setting the compiler option -language:postfixOps.
See the Scaladoc for value scala.language.postfixOps for a discussion
why the feature needs to be explicitly enabled.
  def f = 42 toString
             ^
1 error
  sdk use scala 3.1.0

Using scala version 3.1.0 in this shell.
  scalac -d /tmp postly.scala
-- Error: postly.scala:3:10 ---------------------------------------------------------------------------------------------------------------------
3 |  def f = 42 toString
  |          ^^
  |          postfix operator `toString` needs to be enabled
  |          by making the implicit value scala.language.postfixOps visible.
  |          ----
  |          This can be achieved by adding the import clause 'import scala.language.postfixOps'
  |          or by setting the compiler option -language:postfixOps.
  |          See the Scaladoc for value scala.language.postfixOps for a discussion
  |          why the feature needs to be explicitly enabled.
1 error found

Output

As shown.

Expectation

The ---- is meant to be stripped by the reporter. If the error must be displayed multiple times, the explanatory suffix after the divider can be omitted for the sake of brevity.

➜  scala
Welcome to Scala 3.1.0 (17.0.1, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.

scala> def f = 42 toString
-- Error:
1 |def f = 42 toString
  |        ^^
  |        postfix operator `toString` needs to be enabled
  |        by making the implicit value scala.language.postfixOps visible.
  |        ----
  |        This can be achieved by adding the import clause 'import scala.language.postfixOps'
  |        or by setting the compiler option -language:postfixOps.
  |        See the Scaladoc for value scala.language.postfixOps for a discussion
  |        why the feature needs to be explicitly enabled.

scala> def f = 42 toString
-- Error:
1 |def f = 42 toString
  |        ^^
  |        postfix operator `toString` needs to be enabled
  |        by making the implicit value scala.language.postfixOps visible.
  |        ----
  |        This can be achieved by adding the import clause 'import scala.language.postfixOps'
  |        or by setting the compiler option -language:postfixOps.
  |        See the Scaladoc for value scala.language.postfixOps for a discussion
  |        why the feature needs to be explicitly enabled.

scala>
➜  sdk use scala 2.13.7

Using scala version 2.13.7 in this shell.
➜  scala
Welcome to Scala 2.13.7 (OpenJDK 64-Bit Server VM, Java 17.0.1).
Type in expressions for evaluation. Or try :help.

scala> def f = 42 toString
                  ^
       error: postfix operator toString needs to be enabled
       by making the implicit value scala.language.postfixOps visible.
       This can be achieved by adding the import clause 'import scala.language.postfixOps'
       or by setting the compiler option -language:postfixOps.
       See the Scaladoc for value scala.language.postfixOps for a discussion
       why the feature needs to be explicitly enabled.

scala> def f = 42 toString
                  ^
       error: postfix operator toString needs to be enabled
       by making the implicit value scala.language.postfixOps visible.

scala>
@dwijnand dwijnand added Spree Suitable for a future Spree area:repl area:reporting Error reporting including formatting, implicit suggestions, etc labels Jan 12, 2022
@som-snytt
Copy link
Contributor Author

Different behavior for generated feature warning (as opposed to error)

scala> implicit def f(i: Int): List[Int] = List(i)
1 warning found
-- Feature Warning: -----------------------------------------------------------------------------------------------------------------------------
1 |implicit def f(i: Int): List[Int] = List(i)
  |             ^
  |             Definition of implicit conversion method f should be enabled
  |             by adding the import clause 'import scala.language.implicitConversions'
  |             or by setting the compiler option -language:implicitConversions.
  |             See the Scala docs for value scala.language.implicitConversions for a discussion
  |             why the feature should be explicitly enabled.
def f(i: Int): List[Int]

@SethTisue
Copy link
Member

Tom (@griggt) looked into this some, and we just looked at it together, and we were both surprised to learn that:

  • in Scala 2, the only error message that uses this ---- thing is a general missing-language-import error that applies to postfixOps but also to other language features
  • in Scala 3, the only error message that uses --- was a specific error applying to postfixOps only
  • even that error message was removed by Martin a week ago in Reject postfix ops already in Parser #14677

of course Scala 3 does still have a generic "you need a language import" warning, but the current text of that warning doesn't have ---- in it. but the warning message is in two parts, it's just that the ---- mechanism isn't what makes it have two parts, rather there's custom code, specific to featureWarning, that splits it and suppresses the second part on repeated issuance; the relevant method is featureWarning in report.scala which calls reportNewFeatureUseSite and passes it part 2 of the message.

both Tom and I were surprised to learn that ---- was so rarely used in Scala 2 error messages — I guess because we've both seen the Scala 2 "missing language import" warning about a hundred million times, giving us the impression it was sort of common — and in a sense I suppose it is, if others are seeing the warning often as well

anyway, there are two possible courses of action here:

  • do nothing and figure that in the future if anybody gets an itch to make more two-part error messages, they can generalize the featureWarning code
  • choose to tackle that ourselves now

but in any case, after #14677 this is now a feature request, not a bug.

@SethTisue
Copy link
Member

SethTisue commented Mar 22, 2022

and since it's a minor, speculative feature request, I don't think it's really necessary to transfer the ticket to dotty-feature-requests. closing

@som-snytt
Copy link
Contributor Author

Maybe the feature request would be, "Under -explain, only explain to me once."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:repl area:reporting Error reporting including formatting, implicit suggestions, etc itype:bug Spree Suitable for a future Spree
Projects
None yet
Development

No branches or pull requests

3 participants