Skip to content

Commit

Permalink
Fix scala#4339: Dealias when checking refinements
Browse files Browse the repository at this point in the history
  • Loading branch information
allanrenucci committed Apr 18, 2018
1 parent be52c5a commit f3888c2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions tests/neg/i4339.scala
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit f3888c2

Please sign in to comment.