Skip to content

Inliner fails to properly reduce pure case classes in a few situations #8306

Closed
@fhackett

Description

@fhackett

Setup:

case class A(i: Int)
case class B(a: A)

Note: results are paraphrased, removing some of the more verbose types and qualifications. Assume all the code snippets below are inside some arbitrary inline method that has A and B in scope.

The expected result for all cases is:

3

Inline match around type ascriptions

inline (A(3) : A) match {
  case A(i) => i
}

Result:

val $scrutinee1 = A(3) : A
val $elem1 = $scrutinee1.i
val i = $elem1
i

Inline match with nested patterns

inline B(A(3)) match {
  case B(A(i)) => i
}

Result:

val $scrutinee1 = B(A(3))
val $elem1 = A(3) // so clearly it's trying, it just doesn't keep going...
val $elem2 = $elem1.i
val i = $elem2
i

Notice how it keeps $scrutinee1 around despite no references to it, which might be a bug on its own.

Projecting without an inline match

A(3).i

Result:

A(3).i

It's unclear if this last one is by design, but since this kind of compile-time case class manipulation/destructuring feels like constant folding (and basically is), I've included it.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions