Skip to content

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

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
Iltotore opened this issue Feb 12, 2021 · 0 comments · Fixed by #11391
Closed

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

Iltotore opened this issue Feb 12, 2021 · 0 comments · Fixed by #11391

Comments

@Iltotore
Copy link
Contributor

Iltotore commented Feb 12, 2021

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)

nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Feb 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants