From f3888c2b3a8fad65ca0ed0a77f76859639c88dd8 Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Wed, 18 Apr 2018 15:49:40 +0200 Subject: [PATCH] Fix #4339: Dealias when checking refinements --- .../tools/dotc/transform/ExpandSAMs.scala | 2 +- tests/neg/i4339.scala | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 tests/neg/i4339.scala diff --git a/compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala b/compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala index ef1aca47af89..aa269beea170 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala @@ -88,7 +88,7 @@ class ExpandSAMs extends MiniPhase { cpy.Block(tree)(List(applyDef, isDefinedAtDef), anonCls) } - private def checkRefinements(tpe: Type, pos: Position)(implicit ctx: Context): Type = tpe match { + private def checkRefinements(tpe: Type, pos: Position)(implicit ctx: Context): Type = tpe.dealias match { case RefinedType(parent, name, _) => if (name.isTermName && tpe.member(name).symbol.ownersIterator.isEmpty) // if member defined in the refinement ctx.error("Lambda does not define " + name, pos) diff --git a/tests/neg/i4339.scala b/tests/neg/i4339.scala new file mode 100644 index 000000000000..58150bcb5f74 --- /dev/null +++ b/tests/neg/i4339.scala @@ -0,0 +1,19 @@ +class Test { + def test: Unit = { + val a: PartialFunction[Int, Int]{ def foo: Int } = { case x => x } // error + + type PF = PartialFunction[Int, Int] { def foo: Int } + val b: PF = { case x => x } // error + + type PF1 = PartialFunction[Int, Int] {def foo: Int } + val c: PF1 {} = { case x => x } // error + + type PF2 = PartialFunction[Int, Int] + val d: PF2 {} = { case x => x } + + type PF3 = PartialFunction[Int, Int] {} + val e: PF3 = { case x => x } + + val f: PartialFunction[Int, Int] {} { def foo: Int } = { case x => x } // error + } +}