Closed
Description
Compiler version
3.2.2
Minimized code
object TypeCheck:
def main(args: Array[String]): Unit =
val result =
scala.compiletime.testing.typeChecks(
"trait RecursiveSelfTypeEntity[E <: RecursiveSelfTypeEntity[E]]: \n" +
" self: E => \n" +
" def create(): E \n" +
" def read(id: Long): Option[E] \n" +
" def update(f: E => E): E \n" +
" def delete(id: Long): Unit \n" +
"\n" +
"class Apple extends RecursiveSelfTypeEntity[Apple]: \n" +
" override def create(): Apple = ??? \n" +
" override def read(id: Long): Option[Apple] = ??? \n" +
" override def update(f: Apple => Apple): Apple = ??? \n" +
" override def delete(id: Long): Unit = ??? \n" +
" \n" +
"class Orange extends RecursiveSelfTypeEntity[Orange]: \n" +
" override def create(): Orange = ??? \n" +
" override def read(id: Long): Option[Orange] = ??? \n" +
" override def update(f: Orange => Orange): Orange = ??? \n" +
" override def delete(id: Long): Unit = ??? \n" +
" \n" +
"class Banana extends RecursiveSelfTypeEntity[Apple]: \n" +
" override def create(): Apple = ??? \n" +
" override def read(id: Long): Option[Apple] = ??? \n" +
" override def update(f: Apple => Apple): Apple = ??? \n" +
" override def delete(id: Long): Unit = ???\n"
)
assert(result, "Should fail type check, but it didn't.")
Output
Nothing.
Expectation
It should throw an exception from typeChecks
since Banana
cannot extend from RecursiveSelfTypeEntity[Apple]
Activity
shouldNot compile
giving a false positive scalatest/scalatest#2252odersky commentedon Jul 6, 2023
Bounds tests are run in the phase after type checking. So that's why
typeChecks
fails. We cannot run bounds tests during typer since F-bounds would cause cyclic dependencies.Mitigation: Maybe
scala.compiletime.testing.typeChecks
should run bounds checks after type checking proper succeeds?cheeseng commentedon Sep 24, 2023
@odersky @smarter @dhinojosa Fyi we have another issue reported for
assertDoesNotCompile
that I think is related to this, with perhaps another minimal example?scalatest/scalatest#2283
One side note is that Scala 2's
scala.reflect.macros.Context.typeCheck
worked, so imho this will look like a regression for user migrating from Scala 2 to Scala 3.Extend compiletime.testing.typechecks with certain transform phases (s…
2 remaining items