Skip to content

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

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
reid-spencer opened this issue Mar 4, 2024 · 5 comments
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc area:rewriting tool better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement stat:needs info stat:needs minimization Needs a self contained minimization

Comments

@reid-spencer
Copy link

reid-spencer commented Mar 4, 2024

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:

  • Drop the last line of the message since no attempt to rewrite the code is ever made.
  • If rewriting is an option, place the rewritten code in the error message
  • If rewriting is not an option, provide instructions on where/how to make the needed modifications
@reid-spencer reid-spencer added area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 4, 2024
@Gedochao Gedochao added area:rewriting tool stat:needs info stat:needs minimization Needs a self contained minimization and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Mar 12, 2024
@reid-spencer
Copy link
Author

A test case that details both:

  • a working version with Scala 3.3.3 on commit @bb64512e
  • a failing version with Scala 3.4.0 on @baec8b7b
    can be found in this repository:

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

@winitzki
Copy link

winitzki commented Apr 10, 2024

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
Copy link

yohannj commented May 17, 2024

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
Copy link

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 _))

@som-snytt
Copy link
Contributor

3.6 message is

[error] 25 |  val result = Parsers.parseRule[Long](input, Parsers.allLong(_), true)
[error]    |                                                             ^
[error]    |No given instance of type fastparse.ParsingRun[u] was found for a context parameter of method allLong in object Parsers
[error]    |
[error]    |where:    u is a type variable

The caret points to where the missing implicit would go.

If that message is not meaningful, so that you delete the placeholder, then you get the error reported above, it found a context function ?=> and requires a regular function. I think if those types align, it could suggest the correct code. A placeholder would always align.

This ticket is related to #19680 which also turns on a missing using keyword. There, I asked to be told that I omitted using. The application is more elaborate, or elaborated: an implicit is available, and the explicit arg is misaligned with some other parameter. Perhaps, as suggested on the other ticket, this problem is rare, and any message that is not totally wrong will suffice to get you on track.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc area:rewriting tool better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement stat:needs info stat:needs minimization Needs a self contained minimization
Projects
None yet
Development

No branches or pull requests

6 participants