Skip to content

Commit 7e138cc

Browse files
committed
Fix #3548: set outer select type to be the type enclosing the expected type
Otherwise, ElimOuterSelect will insert `ensureConforms(tp)` in outer test, which causes run-time exeception.
1 parent 88d016c commit 7e138cc

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ object PatternMatcher {
771771
val expectedClass = expectedTp.dealias.classSymbol.asClass
772772
ExplicitOuter.ensureOuterAccessors(expectedClass)
773773
scrutinee.ensureConforms(expectedTp)
774-
.outerSelect(1, expectedOuter.tpe.widen)
774+
.outerSelect(1, expectedClass.owner.typeRef)
775775
.select(defn.Object_eq)
776776
.appliedTo(expectedOuter)
777777
}

tests/run/i3548.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
trait Common {
2+
case class Data(a: String)
3+
}
4+
object O1 extends Common
5+
object O2 extends Common
6+
7+
object Test {
8+
def main(args: Array[String]): Unit = {
9+
10+
val data = O2.Data("test")
11+
12+
// Runtime error: java.lang.ClassCastException: O2$ cannot be cast to O1$
13+
data match {
14+
case O1.Data(s) => println("O1 data")
15+
case O2.Data(s) => println("O2 data")
16+
case _ => println("Unknown")
17+
}
18+
}
19+
}

0 commit comments

Comments
 (0)