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

FTypePolymorphism does not type check correctly using typeChecks #18150

Open
dhinojosa opened this issue Jul 5, 2023 · 2 comments
Open

FTypePolymorphism does not type check correctly using typeChecks #18150

dhinojosa opened this issue Jul 5, 2023 · 2 comments
Labels

Comments

@dhinojosa
Copy link

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]

@odersky
Copy link
Contributor

odersky commented 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?

@odersky odersky added itype:enhancement and removed stat:needs triage Every issue needs to have an "area" and "itype" label itype:bug labels Jul 6, 2023
@smarter smarter added the area:metaprogramming:compiletime The scala.compiletime package label Jul 6, 2023
@cheeseng
Copy link

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants