Skip to content

Eq/Order enum derivation emits "unchecked type test" warning (fails under -Werror) #184

Description

@kubukoz

Summary

Deriving Eq (or Order) for a parameterless enum makes the generated code in EqEnumRule / OrderEnumRule emit a compiler warning:

the type test for E.A cannot be checked at runtime because it refers to an abstract type member or type parameter

Because the warning originates from kindlings' own generated code, users can't fix it at the call site, and any project compiling with -Werror (fatal warnings) fails to build.

Minimal reproduction (scala-cli)

//> using scala 3.8.4
//> using dep com.kubuszok::kindlings-cats-derivation:0.3.1
//> using option -Werror

import cats.Eq
import hearth.kindlings.catsderivation.extensions.*

enum E derives Eq {
  case A, B
}

Compiling yields:

[error] .../hearth/kindlings/catsderivation/internal/compiletime/rules/EqEnumRule.scala:1:1
[error] the type test for E.A cannot be checked at runtime because it refers to an abstract type member or type parameter

Without -Werror it is a [warn] (still emitted on every compile).

Scope

  • Reproduces with Eq (EqEnumRule) and Order (OrderEnumRule) — the generated per-case type test in the enum comparison rules seems to be the common cause.
  • Happens for a minimal 2-case parameterless enum.

Comparison with kittens

kittens (org.typelevel::kittens:3.5.0) derives Eq for the same enum on the same Scala version with no warning:

//> using scala 3.8.4
//> using dep org.typelevel::kittens:3.5.0
import cats.Eq
import cats.derived.*
enum E derives Eq { case A, B }   // compiles clean, no warnings

Environment

  • kindlings-cats-derivation: 0.3.1
  • Scala: 3.8.4
  • scala-cli: 1.15.0, JVM 21

Expected

Generated enum Eq/Order instances should not emit unchecked-type-test warnings (e.g. match on the enum ordinal/==, or generate type tests the compiler can check), so that derivation is clean under -Werror.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions