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

compileErrors doesn't return all errors #750

Closed
robstoll opened this issue Mar 5, 2024 · 8 comments
Closed

compileErrors doesn't return all errors #750

robstoll opened this issue Mar 5, 2024 · 8 comments

Comments

@robstoll
Copy link
Contributor

robstoll commented Mar 5, 2024

Consider the following:

assertNoDiff(
   compileErrors("1.isInstanceOf[String]"),
  "cannot test if value of type Int is a reference of class String"
)
@erikerlandson
Copy link

I am also seeing this, in coulomb. My compiler is 3.4.2-RC1-xxxxx-NIGHTLY

// this is returning empty error list
val x = compileErrors("3.withUnit[Second] * 5d.withUnit[Kilogram]")
println(s"x= $x")

However if I try to compile, this errors out (as it should)

val x = 3.withUnit[Second] * 5d.withUnit[Kilogram]
[error] -- [E172] Type Error: /home/eje/git/coulomb/core/src/test/scala/coulomb/quantity.scala:232:58 
[error] 232 |        val x = 3.withUnit[Second] * 5d.withUnit[Kilogram]
[error]     |                                                          ^
[error]     |No given instance of type algebra.ring.MultiplicativeSemigroup[Double | Int] was found for parameter alg of method * in object Quantity
[error] one error found

@erikerlandson
Copy link

In my case this issue may be duplicate of #711

@tgodzik
Copy link
Contributor

tgodzik commented Apr 15, 2024

Looking again at this, it seems in the first case it might be an issue within the compiler, though ideally isInstanceOf would just return false instead of failing. So it seems the munit behaviour is by mistake correct.

@erikerlandson was your issue fixed by using the method in #711 ?

@robstoll
Copy link
Contributor Author

@tgodzik I am afraid I am not sure if I get what you mean. I guess you mean the underlying of compileErrors in the compiler is buggy right and that's way it is hard for munit to fix this. Correct?

@tgodzik
Copy link
Contributor

tgodzik commented Apr 16, 2024

@tgodzik I am afraid I am not sure if I get what you mean. I guess you mean the underlying of compileErrors in the compiler is buggy right and that's way it is hard for munit to fix this. Correct?

Actually, we were missing transient keyword, which is suggested to be used in this specific case. You can try using this method:

transparent inline def compileErrorsFixed(inline code: String): String = {
    val errors = scala.compiletime.testing.typeCheckErrors(code)
    errors
      .map { error =>
        val indent = " " * (error.column - 1)
        val trimMessage = error.message.linesIterator
          .map { line =>
            if line.matches(" +") then ""
            else line
          }
          .mkString("\n")
        val separator = if error.message.contains('\n') then "\n" else " "
        s"error:$separator$trimMessage\n${error.lineContent}\n$indent^"
      }
      .mkString("\n")
  }

explicitely to see if adding the keyword helps in your case

@erikerlandson
Copy link

@tgodzik coincidentally I made a design change to what I was doing and it caused this error to stop happening to me. It must have changed the specific compiler error so that compileErrors was catching it. So my code no longer reproduces this to test a fix :/

@tgodzik
Copy link
Contributor

tgodzik commented Apr 16, 2024

Ok, let us know if anything pops up again.

Coming back to the initial error in this issue it seems this is caused by a bug in the compiler or might actually be on purpose. Will ask.

@tgodzik
Copy link
Contributor

tgodzik commented Apr 16, 2024

So it looks like this is an actual expected behaviour as the error in 1.isInstanceOf[String] is produced in another phase. If needed please raise an issue in the compiler @robstoll

@tgodzik tgodzik closed this as not planned Won't fix, can't repro, duplicate, stale Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants