scala / scala3

The Scala 3 compiler, also known as Dotty.
https://dotty.epfl.ch
Apache License 2.0
5.89k stars 1.06k forks source link

The default arguments are not found during rechecking #17012

Open noti0na1 opened 1 year ago

noti0na1 commented 1 year ago

We are working on an experiment feature based on Recheck. During our testing on community projects, we have observed some unusual typing behaviors that we believe are caused by a bug in Recheck.

Compiler version

3.3.1-RC1-bin-SNAPSHOT-nonbootstrapped-git-c1809bc

Minimized code

I couldn't minimize the code that triggers the issue. Here is the instruction on how to reproduce the error:

  1. enable -Yrecheck-test in fansi, by adding def scalacOptions = Seq("-Yrecheck-test") to build.sc (to both FansiMainModule and FansiTestModule)
  2. run community-build/testOnly -- *fansi

Output

[error] -- [E007] Type Mismatch Error: dotty/community-build/community-projects/fansi/fansi/test/src/fansi/FansiTests.scala:28:14 
[error] 28 |      val r = fansi.Str(rgbOps).render
[error]    |              ^^^^^^^^^
[error]    |              Found:    fansi.Str.apply$default$2.type
[error]    |              Required: fansi.ErrorMode

It seems the default argument is not found on class fansi.Str, so we get NoType from fansi.Str.apply$default$2.

The code of fansi.Str looks like:

class Str private(private val chars: Array[Char], private val colors: Array[Str.State]) {
  ...
}

object Str {

  def apply(raw: CharSequence, errorMode: ErrorMode = ErrorMode.Throw): fansi.Str = {
    ...
  }

  ...
}

and the place causing the error:

val rgbOps = s"+++$R---$G***$B///"
...
val r = fansi.Str(rgbOps).render // error

cc: @e45lee @olhotak

e45lee commented 1 year ago

This appears to be an issue in the utest runner library -- the code that is generated by the macros in that library do not pass the checks in -Xcheck-macros.