From 76ba6b27e2ec64017ad10f98f83a2d53ea0446b8 Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Tue, 17 Apr 2018 22:30:14 +0200 Subject: [PATCH 1/2] Fix #4315: handle local child from scalac --- .../src/dotty/tools/dotc/transform/patmat/Space.scala | 2 ++ tests/patmat/i4315.scala | 8 ++++++++ 2 files changed, 10 insertions(+) create mode 100644 tests/patmat/i4315.scala diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 2cb690805a9c..0051ec15208f 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -497,6 +497,8 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { def refine(parent: Type, child: Symbol): Type = { if (child.isTerm && child.is(Case, butNot = Module)) return child.termRef // enum vals always match + if (child.name == tpnme.LOCAL_CHILD) return child.typeRef + val childTp = if (child.isTerm) child.termRef else child.typeRef val resTp = instantiate(childTp, parent)(ctx.fresh.setNewTyperState()) diff --git a/tests/patmat/i4315.scala b/tests/patmat/i4315.scala new file mode 100644 index 000000000000..d06d53493d45 --- /dev/null +++ b/tests/patmat/i4315.scala @@ -0,0 +1,8 @@ +import scala.concurrent.duration.{Duration, FiniteDuration} + +class Test { + def test(d: Duration) = d match { + case finite: FiniteDuration => + case d => + } +} From 8d7c53f531d44309642355eed10c0ee33e97436b Mon Sep 17 00:00:00 2001 From: liu fengyun Date: Wed, 18 Apr 2018 17:52:22 +0200 Subject: [PATCH 2/2] add comments: address review --- .../src/dotty/tools/dotc/transform/patmat/Space.scala | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala index 0051ec15208f..bb53e9f81562 100644 --- a/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala +++ b/compiler/src/dotty/tools/dotc/transform/patmat/Space.scala @@ -497,6 +497,15 @@ class SpaceEngine(implicit ctx: Context) extends SpaceLogic { def refine(parent: Type, child: Symbol): Type = { if (child.isTerm && child.is(Case, butNot = Module)) return child.termRef // enum vals always match + // is a place holder from Scalac, it is hopeless to instantiate it. + // + // Quote from scalac (from nsc/symtab/classfile/Pickler.scala): + // + // ...When a sealed class/trait has local subclasses, a single + // class symbol is added as pickled child + // (instead of a reference to the anonymous class; that was done + // initially, but seems not to work, ...). + // if (child.name == tpnme.LOCAL_CHILD) return child.typeRef val childTp = if (child.isTerm) child.termRef else child.typeRef