Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minimal support for dependent case classes #21698

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Commits on Oct 5, 2024

  1. Support refinement type on enum case

    This used to fail with:
        trait <refinement> in value x extends enum EC, but extending enums is prohibited.
    smarter committed Oct 5, 2024
    Configuration menu
    Copy the full SHA
    db81e44 View commit details
    Browse the repository at this point in the history
  2. Minimal support for dependent case classes

    This lets us write:
    
        trait A:
          type B
    
        case class CC(a: A, b: a.B)
    
    Pattern matching works but isn't dependent yet:
    
        x match
          case CC(a, b) =>
            val a1: A = a
            // Dependent pattern matching is not currently supported
            // val b1: a1.B = b
            val b1 = b // Type is CC#a.B
    
    (for my usecase this isn't a problem, I'm working on a type constraint API
    which lets me write things like `case class CC(a: Int, b: Int
    GreaterThan[a.type])`)
    
    Because case class pattern matching relies on the product selectors `_N`, making
    it dependent is a bit tricky, currently we generate:
    
        case class CC(a: A, b: a.B):
          def _1: A = a
          def _2: a.B = b
    
    So the type of `_2` is not obviously related to the type of `_1`, we probably
    need to change what we generate into:
    
        case class CC(a: A, b: a.B):
          @uncheckedStable def _1: a.type = a
          def _2: _1.B = b
    
    But this can be done in a separate PR.
    
    Fixes scala#8073.
    smarter committed Oct 5, 2024
    Configuration menu
    Copy the full SHA
    e5327ac View commit details
    Browse the repository at this point in the history