Skip to content

Implement parameter dependent case classes #8073

Closed
@odersky

Description

@odersky

minimized example

From #8069:

trait A:
  type B

enum Test:
  case Test(a: A, b: a.B)   // error: Implementation restriction: case classes cannot have dependencies between parameters

case class Test2(a: A, b: a.B) // error: Implementation restriction: case classes cannot have dependencies 

It would be great if we could lift the implementation restriction and admit case classes (and enum cases) with parameter dependencies.

To get there, we need a systematic study where we have to do the right substitutions.

One immediate problem, which caused #8069 is that fromProduct does not work as given since it
casts to unsubstituted parameter types. E.g. for class Test2, fromProduct would contain code like this:

new C(
  x.productElement(0).asInstanceOf[A],
  x.productElement(1).asInstanceOf[a.B])

where the a in a.B is unbound.

I suspect there will also be other problems with pattern matching, and maybe elsewhere. So it will require a focussed effort to get there. But the benefits (dependent ADTs) would be potentially very significant!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions