Skip to content

typeCheckErrors reports false errors for enum and case object definitions #23578

@katrinafyi

Description

@katrinafyi

scala.compiletime.testing.typeChecks and typeCheckErrors will report type-check failure for case objects and enums which contain at least one case with no parameters. this seems to only happen when called outside of an inline def.

Compiler version

bug reproduced on 3.3.6, 3.7.0.

tested 3.3.4, 3.3.5 and 3.7.1 do not have the bug

Minimized code

3.3.6 scastie https://scastie.scala-lang.org/3o5RBHQPQje29ie9erAO5A

import scala.compiletime.testing.{typeChecks, typeCheckErrors}

println(typeCheckErrors("""
enum E {
  case E1
}
case object A
"""))
println("------")

def go(): Unit = {
  println(typeCheckErrors("""
  enum E {
    case E1
  }
  case object A
  """))
}
go()
println("------")

inline def go2(): Unit = {
  println(typeCheckErrors("""
  enum E {
    case E1
  }
  case object A
  """))
}
go2()
println("------")

Output

note that the list of errors has one for both the case object and the enum definitions.

note that the last test, called from within the inline def, shows no errors (as expected).

List(Error(object creation impossible, since:
it has 3 unimplemented members.
/** As seen from module class A$, the missing signatures are as follows.
 *  For convenience, these are usable as stub implementations.
 */
  // Members declared in scala.Equals
  def canEqual(that: Any): Boolean = ???
  
  // Members declared in scala.Product
  def productArity: Int = ???
  def productElement(n: Int): Any = ???
,case object A,12,Typer), Error(object creation impossible, since def ordinal: Int in trait Enum in package scala.reflect is not defined ,  case E1,2,Typer))
------
List(Error(object creation impossible, since:
it has 3 unimplemented members.
/** As seen from module class A$, the missing signatures are as follows.
 *  For convenience, these are usable as stub implementations.
 */
  // Members declared in scala.Equals
  def canEqual(that: Any): Boolean = ???
  
  // Members declared in scala.Product
  def productArity: Int = ???
  def productElement(n: Int): Any = ???
,  case object A,14,Typer), Error(object creation impossible, since def ordinal: Int in trait Enum in package scala.reflect is not defined ,    case E1,4,Typer))
------
List()
------

Expectation

first, the behaviour of typeCheckErrors should not change depending on whether it's called from within an inline def.

secondly, typeChecks/typeCheckErrors should report no type errors for these valid code snippets.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions