Skip to content

Commit f3888c2

Browse files
committed
Fix #4339: Dealias when checking refinements
1 parent be52c5a commit f3888c2

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

compiler/src/dotty/tools/dotc/transform/ExpandSAMs.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class ExpandSAMs extends MiniPhase {
8888
cpy.Block(tree)(List(applyDef, isDefinedAtDef), anonCls)
8989
}
9090

91-
private def checkRefinements(tpe: Type, pos: Position)(implicit ctx: Context): Type = tpe match {
91+
private def checkRefinements(tpe: Type, pos: Position)(implicit ctx: Context): Type = tpe.dealias match {
9292
case RefinedType(parent, name, _) =>
9393
if (name.isTermName && tpe.member(name).symbol.ownersIterator.isEmpty) // if member defined in the refinement
9494
ctx.error("Lambda does not define " + name, pos)

tests/neg/i4339.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Test {
2+
def test: Unit = {
3+
val a: PartialFunction[Int, Int]{ def foo: Int } = { case x => x } // error
4+
5+
type PF = PartialFunction[Int, Int] { def foo: Int }
6+
val b: PF = { case x => x } // error
7+
8+
type PF1 = PartialFunction[Int, Int] {def foo: Int }
9+
val c: PF1 {} = { case x => x } // error
10+
11+
type PF2 = PartialFunction[Int, Int]
12+
val d: PF2 {} = { case x => x }
13+
14+
type PF3 = PartialFunction[Int, Int] {}
15+
val e: PF3 = { case x => x }
16+
17+
val f: PartialFunction[Int, Int] {} { def foo: Int } = { case x => x } // error
18+
}
19+
}

0 commit comments

Comments
 (0)