Skip to content

confusing Implicit parameters should be provided with a using clause message if implicit default param #22567

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
xuwei-k opened this issue Feb 9, 2025 · 3 comments · Fixed by #22765
Assignees
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement

Comments

@xuwei-k
Copy link
Contributor

xuwei-k commented Feb 9, 2025

Compiler version

3.7.0-RC1-bin-20250207-d60a914-NIGHTLY

Minimized example

a1/src/main/scala/A1.scala

object A1 {
  def f1(implicit x1: String, x2: Int = 2): Unit = ()
}

a2/src/main/scala/A2.scala

object A2 {
  given String = "s"

  def f2 = A1.f1
}

build.sbt

val a1 = project.settings(
  scalaVersion := "2.13.16"
)

val a2 = project.settings(
  scalaVersion := "3.7.0-RC1-bin-20250207-d60a914-NIGHTLY"
).dependsOn(a1)

Output Error/Warning message

[warn] -- Warning: example-implicit-using-default-project/a2/src/main/scala/A2.scala:4:16 
[warn] 4 |  def f2 = A1.f1
[warn]   |                ^
[warn]   |Implicit parameters should be provided with a `using` clause.
[warn]   |This code can be rewritten automatically under -rewrite -source 3.7-migration.
[warn]   |To disable the warning, please use the following option: 
[warn]   |  "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s"
[warn] one warning found

Why this Error/Warning was not helpful

This is implicit params but not call with explicit.

Suggested improvement

Note

@xuwei-k xuwei-k 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 Feb 9, 2025
@hamzaremmal hamzaremmal self-assigned this Feb 10, 2025
@xuwei-k
Copy link
Contributor Author

xuwei-k commented Feb 10, 2025

unnecessary Scala 2 cross build. here is more simple example

Welcome to Scala 3.7.0-RC1-bin-20250207-d60a914-NIGHTLY-git-d60a914 (21.0.6, Java OpenJDK 64-Bit Server VM).
Type in expressions for evaluation. Or try :help.
                                                                                                                                                                                                                        
scala> def f1(implicit x1: String, x2: Int = 2): Unit = ()
def f1(implicit x1: String, x2: Int): Unit
                                                                                                                                                                                                                        
scala> given String = "s"
lazy val given_String: String
                                                                                                                                                                                                                        
scala> f1
1 warning found
-- Warning: --------------------------------------------------------------------
1 |f1
  |  ^
  |Implicit parameters should be provided with a `using` clause.
  |To disable the warning, please use the following option: 
  |  "-Wconf:msg=Implicit parameters should be provided with a `using` clause:s"

@som-snytt
Copy link
Contributor

The tricky bit (IIRC) is that Scala 2 does not honor default args if implicits are supplied implicitly; that is a Scala 3 innovation.

@som-snytt
Copy link
Contributor

Actually this is fixed by #22458

The message is on 3.nightly 2f639e2 but not when I cherry-pick c37dc8b

hamzaremmal added a commit to hamzaremmal/scala3 that referenced this issue Mar 11, 2025
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 better-errors Issues concerned with improving confusing/unhelpful diagnostic messages itype:enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants