Skip to content

Commit 4f53a1d

Browse files
authored
Merge pull request #2158 from dotty-staging/fix-i2165
Fix #2156
2 parents f75caad + f370799 commit 4f53a1d

File tree

4 files changed

+48
-22
lines changed

4 files changed

+48
-22
lines changed

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ class ClassfileParser(
661661
for (entry <- innerClasses.values) {
662662
// create a new class member for immediate inner classes
663663
if (entry.outerName == currentClassName) {
664-
val file = ctx.platform.classPath.findSourceFile(entry.externalName.toString) getOrElse {
664+
val file = ctx.platform.classPath.findBinaryFile(entry.externalName.toString) getOrElse {
665665
throw new AssertionError(entry.externalName)
666666
}
667667
enterClassAndModule(entry, file, entry.jflags)

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

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -848,26 +848,21 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {
848848

849849
val nextBinder = afterTest.asTerm
850850

851-
def needsOuterTest(patType: Type, selType: Type, currentOwner: Symbol): Boolean = {
851+
def outerTestNeeded(implicit ctx: Context): Boolean = {
852852
// See the test for SI-7214 for motivation for dealias. Later `treeCondStrategy#outerTest`
853853
// generates an outer test based on `patType.prefix` with automatically dealises.
854-
patType.dealias match {
855-
case tref @ TypeRef(pre, name) =>
856-
(pre ne NoPrefix) && tref.symbol.isClass &&
857-
ExplicitOuter.needsOuterIfReferenced(tref.symbol.asClass)
854+
expectedTp.dealias match {
855+
case tref @ TypeRef(pre: SingletonType, name) =>
856+
val s = tref
857+
s.symbol.isClass &&
858+
ExplicitOuter.needsOuterIfReferenced(s.symbol.asClass)
858859
case _ =>
859860
false
860861
}
861862
}
862863

863864
override lazy val introducedRebindings = NoRebindings
864865

865-
def outerTestNeeded = {
866-
val np = expectedTp.normalizedPrefix
867-
val ts = np.termSymbol
868-
(ts ne NoSymbol) && needsOuterTest(expectedTp, testedBinder.info, ctx.owner)
869-
}
870-
871866
// the logic to generate the run-time test that follows from the fact that
872867
// a `prevBinder` is expected to have type `expectedTp`
873868
// the actual tree-generation logic is factored out, since the analyses generate Cond(ition)s rather than Trees

compiler/src/dotty/tools/io/ClassPath.scala

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,22 +240,16 @@ abstract class ClassPath {
240240
def findClass(name: String): Option[AnyClassRep] =
241241
name.splitWhere(_ == '.', doDropIndex = true) match {
242242
case Some((pkg, rest)) =>
243-
val rep = packages find (_.name == pkg) flatMap (_ findClass rest)
244-
rep map {
245-
case x: ClassRep => x
246-
case x => throw new FatalError("Unexpected ClassRep '%s' found searching for name '%s'".format(x, name))
247-
}
243+
packages find (_.name == pkg) flatMap (_ findClass rest)
248244
case _ =>
249245
classes find (_.name == name)
250246
}
251247

252-
def findSourceFile(name: String): Option[AbstractFile] =
253-
findClass(name) match {
254-
case Some(ClassRep(Some(x: AbstractFile), _)) => Some(x)
255-
case _ => None
256-
}
248+
def findBinaryFile(name: String): Option[AbstractFile] =
249+
findClass(name).flatMap(_.binary)
257250

258251
def sortString = join(split(asClasspathString).sorted: _*)
252+
259253
override def equals(that: Any) = that match {
260254
case x: ClassPath => this.sortString == x.sortString
261255
case _ => false

tests/run/i2156.scala

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
class Outer {
2+
3+
case class Inner()
4+
5+
val inner: Inner = new Inner
6+
7+
def checkInstance(o: Outer) =
8+
o.inner.isInstanceOf[this.Inner]
9+
10+
def checkPattern1(i: Any) =
11+
i match {
12+
case _: Inner => true
13+
case _ => false
14+
}
15+
16+
def checkPattern2(i: Any) =
17+
i match {
18+
case Inner() => true
19+
case _ => false
20+
}
21+
22+
def checkEquals(o: Outer) =
23+
o.inner == inner
24+
}
25+
26+
object Test {
27+
28+
def main(args: Array[String]) = {
29+
val o1 = new Outer
30+
val o2 = new Outer
31+
assert(o1.checkInstance(o2)) // ok
32+
assert(!o1.checkPattern1(o2.inner)) // ok under scalac, fails for dotc-compiled code
33+
assert(!o1.checkPattern2(o2.inner)) // ok under scalac, fails for dotc-compiled code
34+
assert(!o1.checkEquals(o2)) // ok under scalac, fails for dotc-compiled code
35+
}
36+
}
37+

0 commit comments

Comments
 (0)