Skip to content

Variance not copied into enum case class type parameters #9260

Closed
@bishabosha

Description

@bishabosha

Minimized code

package asts

enum Ast[-T >: Null]:
  case DefDef()

trait AstImpl[T >: Null]:
  type Ast = asts.Ast[T]
  type DefDef = Ast.DefDef[T]
end AstImpl

object untpd extends AstImpl[Null]:

  def DefDef(ast: Ast): DefDef = ast match
    case ast: DefDef => ast

end untpd

Output

-- Warning: Ast.scala:24:9 -----------------------------------------------------
24 |    case ast: DefDef => ast
   |         ^^^^^^^^^^^
   |        the type test for asts.untpd.DefDef cannot be checked at runtime
1 warning found

Expectation

compile as in 0.24.0-RC1

Notes

if we instead explicitly copy the variance from the parent to the case, then the warning goes away:

enum Ast[-T >: Untyped]:
  // case DefDef()
  case DefDef[-T >: Untyped]() extends Ast[T]

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions