scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.83k stars 1.05k forks source link

Error about a missing `using` clause incorrectly suggests use of -rewrite to fix. #19872

Open reid-spencer opened 7 months ago

reid-spencer commented 7 months ago

Compiler version

3.4.0

Minimized example

A code example is not highly relevant to this issue, but you can find one here:

Output Error/Warning message

[error] 60 |    parseRule[Root](input, root(_), withVerboseFailures) {
[error]    |                           ^^^^
[error]    |                           Context bounds will map to context parameters.
[error]    |                           A `using` clause is needed to pass explicit arguments to them.
[error]    |                           This code can be rewritten automatically under -rewrite -source 3.4-migration.
>print scalacOptions
* -deprecation
* -feature
* -new-syntax
* -explain-types
* -Werror
* -pagewidth:120
* -rewrite
* -source
* 3.4-migration
* -explain

Why this Error/Warning was not helpful

The direction to use the -rewrite -source 3.4-migration option isn't applicable or helpful. As you can see, both these options were provided to the compiler. It rewrote nothing. Furthermore, it is not clear where this using clause should be placed.

Suggested improvements

A few ideas:

reid-spencer commented 6 months ago

A test case that details both:

https://github.com/reid-spencer/scala-3.4-19872

winitzki commented 5 months ago

Here is a smaller example where Scala 3.4.1 gives this warning.

This issue has nothing to do with fastparse. It's just the usage pattern for the context bound.

{
  def test[A : List] = true             // Pretend that List[A] will be an implicit value in context.
  test(_)  
}
[warn] Context bounds will map to context parameters.
[warn] A `using` clause is needed to pass explicit arguments to them.
[warn] This code can be rewritten automatically under -rewrite -source 3.4-migration.
[warn]   test(_)
[warn]   ^^^^

The same warning happens with test[Int](_) and when an implicit value List[Int] is available in scope.

yohannj commented 4 months ago

Is it exactly the same though? In the other issue, it says that it compiles fine with "-source:future".

Using the code below and "-source:future", I get the error message:

Found:    (fastparse.ParsingRun[?]) ?=> fastparse.ParsingRun[Unit]
Required: fastparse.ParsingRun[?] => fastparse.ParsingRun[Unit]
import fastparse.*
import fastparse.NoWhitespace.*

@main def app: Unit =
  def foo[$: P]: P[Unit] = P("bar")
  parse("", foo)

Running the rewriting rule of 3.4, it adds a using just before the argument name which doesn't compile at all.

import fastparse.*
import fastparse.NoWhitespace.*

@main def app: Unit =
  def foo[$: P]: P[Unit] = P("bar")
  parse("", using foo)
valmirjunior0088 commented 3 months ago

Hello!

I also ran against this problem but I found a solution that I'm sharing here in case anyone else is still running up against it. I made it work by putting the using keyword right before the implicit argument that the parser definition requires, like:

parse("", foo(using _))