Skip to content

Inhabit bad bounds with recursive member val #23520

Open
@EugeneFlesselle

Description

@EugeneFlesselle

Compiler version

Scala compiler version 3.7.3-RC1

Minimized code

object A:
  val p: { type X >: Any <: Nothing } = p // ok 

@main def Test =
  val y: Int = "hi" : A.p.X // java.lang.ClassCastException: class java.lang.String cannot be cast to class scala.runtime.Nothing

Expectation

I would expect this to type check (for recursive vals in objects) but diverge at run-time.

Note that we report an error for recursive vals when in a def:

def A =
  val p: { type X >: Any <: Nothing } = p
  // error: p is a forward reference extending over the definition of p

Metadata

Metadata

Assignees

No one assigned

    Labels

    itype:bugitype:soundnessSoundness bug (it lets us compile code that crashes at runtime with a ClassCastException)stat:needs triageEvery issue needs to have an "area" and "itype" label

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions