Skip to content
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

custom implicitNotFound ignored when unrelated default argument is inserted #19594

Closed
valencik opened this issue Feb 1, 2024 · 3 comments · Fixed by #19737
Closed

custom implicitNotFound ignored when unrelated default argument is inserted #19594

valencik opened this issue Feb 1, 2024 · 3 comments · Fixed by #19737
Assignees
Labels
area:annotations itype:bug regression This worked in a previous version but doesn't anymore
Milestone

Comments

@valencik
Copy link
Contributor

valencik commented Feb 1, 2024

Compiler version

3.1.3+
(3.1.2 is the last version where the implicitNotFound is not ignored)

Minimized code

import scala.annotation.implicitNotFound
import scala.compiletime.testing.*

@implicitNotFound("Can you see me?!")
trait Compare[A, B]

object minimunit {

  def assertEquals[A, B](
    a: A,
    b: B,
    // The presence of the below default argument prevents the `implicitNotFound` message from appearing
    // in the error output of `typeCheckErrors` in Scala +3.1.3
    clue: => Any = "values are not the same"
  )(implicit comp: Compare[A, B]): Unit = ()

  transparent inline def compileErrors(inline code: String): List[Error] =
    typeCheckErrors(code)
}

object example extends App {
  val errors = minimunit.compileErrors("minimunit.assertEquals(true, 1)")
  println(errors)
}

Output

Scala 3.1.3

scala-cli run --scala-version 3.1.3 minimunit.scala

List(Error(missing argument for parameter comp of method assertEquals in object minimunit: (implicit comp: Compare[Boolean, Int]): Unit,minimunit.assertEquals(true, 1),22,Typer))

Scala 3.1.2

scala-cli run --scala-version 3.1.2 minimunit.scala

List(Error(Can you see me?!,minimunit.assertEquals(true, 1),31,Typer))

Expectation

The implicitNotFound message should appear whether or not there is a default argument involved.

If we remove the clue: => Any = "values are not the same" line, the implicitNotFound message is again returned on Scala versions greater than 3.1.2

I encountered this issue when trying to upgrade munit to Scala 3.3.1
scalameta/munit#733

@valencik valencik added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 1, 2024
@Gedochao Gedochao added area:annotations regression This worked in a previous version but doesn't anymore and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Feb 1, 2024
@Gedochao
Copy link
Contributor

Gedochao commented Feb 1, 2024

Happens also on 3.4.1-RC1-bin-20240131-2b40f55-NIGHTLY

@bishabosha bishabosha changed the title implicitNotFound ignored when callsite has default argument custom implicitNotFound ignored when unrelated default argument is inserted Feb 1, 2024
@valencik
Copy link
Contributor Author

valencik commented Feb 1, 2024

I should add that you don't need the typeCheckErrors to get this behaviour.

Given the following:

import scala.annotation.implicitNotFound

@implicitNotFound("Can you see me?!")
trait Compare[A, B]

object minimunit {

  def assertEquals[A, B](
    a: A,
    b: B,
    // The presence of the below default argument prevents the `implicitNotFound` message from appearing
    // in the error output of `typeCheckErrors` in Scala +3.1.3
    clue: => Any = "values are not the same"
  )(implicit comp: Compare[A, B]): Unit = ()
}

object example extends App {
  minimunit.assertEquals(true, 1)
}

On +3.1.3 we get a compile error:

[error] missing argument for parameter comp of method assertEquals in object minimunit: (implicit comp: Compare[Boolean, Int]): Unit
[error]   minimunit.assertEquals(true, 1)
[error]   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

And on 3.1.2 we see the implicitNotFound instead:

[error] Can you see me?!
[error]   minimunit.assertEquals(true, 1)
[error]                                  ^

@valencik
Copy link
Contributor Author

@Kordyjan should I open another issue for the solution in #19737 to be back ported to a Scala LTS version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:annotations itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
4 participants