Skip to content

"AssertionError: orphan parameter reference" on intersection type destructuring in match types #9757

Closed
@felher

Description

@felher

Hey folks.

I wondered if one could destructure intersection types using match types so I tried it but got an exception when compiling. So regardless of whether what I'm doing here makes any sense, @smarter assured me on gitter that when it crashes, it's a compiler bug. So here's the report:

Minimized code

type RemoveFrom[R, A] = R match {
  case A & newType => newType
}

def removeOnePart[R, PartR, A](f: R => A, partR: PartR): RemoveFrom[R, PartR] => A = ???

trait A {}
trait B {}

val f: (A & B) => Int = ???
val f2 = removeOnePart(f, new A {})

Output

java.lang.AssertionError: assertion failed: orphan parameter reference: TypeParamRef(newType) while compiling /tmp/scastie8052777791899749308/src/main/scala/main.scala

Expectation

I didn't have any expectation other than the compiler not crashing.

Here is a scastie which shows the issue: https://scastie.scala-lang.org/v5nJCPnxSMGKtsZQInzgYw

PS: I know that I can't provide an implementation for (the unconstraint version of) removeOnePart, I just wanted to check whether I can get it to compile.

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions