Skip to content

Wrong report.error message in macro when calling it in an implicit function  #11386

Closed
@Iltotore

Description

@Iltotore

Compiler version

3.0.0-M3

Minimized code

Main.scala

import test._

object Main {
  
  @main def dottyTest(): Unit = {
    dummy(1)
  }
  
  def dummy(msg: String): Unit = println(msg) //A simple dummy method to call implicitly test.int2String
}

test.scala

import scala.language.implicitConversions
import scala.quoted._

object test {

  inline implicit def int2String(inline i: Int): String = {
    notNull(i)
    String.valueOf(i)
  }

  inline def notNull(inline i: Int): Unit = ${notNullImpl('i)}

  def notNullImpl(expr: Expr[Int])(using quotes: Quotes): Expr[Unit] = {
    expr.value.foreach(i => if(i == 0) quotes.reflect.report.error("test"))
    '{()}
  }
}

Output

Using a non-null Int: OK

The code compiles and works as expected

Using zero: dummy(0)

[info] Compiling 1 Scala source to C:\Users\rapha\IdeaProjects\ScalaLint\out\main\compile\dest\classes ...
[error] -- [E007] Type Mismatch Error: C:\Users\rapha\IdeaProjects\ScalaLint\main\src\io\github\iltotore\scalalint\Main.scala:19:10
[error] 19 |    dummy(0)
[error]    |          ^
[error]    |          Found:    (0 : Int)
[error]    |          Required: String
[error] one error found

Using zero but calling the conversion method explicitly: OK

[info] Compiling 1 Scala source to C:\Users\rapha\IdeaProjects\ScalaLint\out\main\compile\dest\classes ...
[error] -- Error: C:\Users\rapha\IdeaProjects\ScalaLint\main\src\io\github\iltotore\scalalint\Main.scala:19:20
[error] 19 |    dummy(int2String(0))
[error]    |          ^^^^^^^^^^^^^
[error]    |          test
[error]    | This location contains code that was inlined from Main.scala:19
[error]    | This location contains code that was inlined from test.scala:9

This is the expected message

Expectation

The compiler should show the test error message like in the third case (Using zero but calling the method explicitly)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions