Skip to content

custom implicitNotFound ignored when unrelated default argument is inserted #19594

Closed
@valencik

Description

@valencik

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

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions