Skip to content

FTypePolymorphism does not type check correctly using typeChecks #18150

Closed
@dhinojosa

Description

@dhinojosa

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

odersky

odersky commented on Jul 6, 2023

@odersky
Contributor

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

cheeseng commented on Sep 24, 2023

@cheeseng

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

added
area:reportingError reporting including formatting, implicit suggestions, etc
on Jul 4, 2024
added a commit that references this issue on Jan 9, 2025
d7dc2a6

2 remaining items

Loading
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

    Development

    Participants

    @smarter@dhinojosa@odersky@cheeseng@Gedochao

    Issue actions

      FTypePolymorphism does not type check correctly using `typeChecks` · Issue #18150 · scala/scala3