Skip to content

Commit df48ce1

Browse files
authored
Merge pull request #4334 from dotty-staging/fix-4315
Fix #4315: handle local child from scalac
2 parents 553ead0 + 8d7c53f commit df48ce1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -497,6 +497,17 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic {
497497
def refine(parent: Type, child: Symbol): Type = {
498498
if (child.isTerm && child.is(Case, butNot = Module)) return child.termRef // enum vals always match
499499

500+
// <local child> is a place holder from Scalac, it is hopeless to instantiate it.
501+
//
502+
// Quote from scalac (from nsc/symtab/classfile/Pickler.scala):
503+
//
504+
// ...When a sealed class/trait has local subclasses, a single
505+
// <local child> class symbol is added as pickled child
506+
// (instead of a reference to the anonymous class; that was done
507+
// initially, but seems not to work, ...).
508+
//
509+
if (child.name == tpnme.LOCAL_CHILD) return child.typeRef
510+
500511
val childTp = if (child.isTerm) child.termRef else child.typeRef
501512

502513
val resTp = instantiate(childTp, parent)(ctx.fresh.setNewTyperState())

tests/patmat/i4315.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.concurrent.duration.{Duration, FiniteDuration}
2+
3+
class Test {
4+
def test(d: Duration) = d match {
5+
case finite: FiniteDuration =>
6+
case d =>
7+
}
8+
}

0 commit comments

Comments
 (0)