Skip to content

Fix #2156 #2158

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ class ClassfileParser(
for (entry <- innerClasses.values) {
// create a new class member for immediate inner classes
if (entry.outerName == currentClassName) {
val file = ctx.platform.classPath.findSourceFile(entry.externalName.toString) getOrElse {
val file = ctx.platform.classPath.findBinaryFile(entry.externalName.toString) getOrElse {
throw new AssertionError(entry.externalName)
}
enterClassAndModule(entry, file, entry.jflags)
Expand Down
17 changes: 6 additions & 11 deletions compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala
Original file line number Diff line number Diff line change
Expand Up @@ -848,26 +848,21 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {

val nextBinder = afterTest.asTerm

def needsOuterTest(patType: Type, selType: Type, currentOwner: Symbol): Boolean = {
def outerTestNeeded(implicit ctx: Context): Boolean = {
// See the test for SI-7214 for motivation for dealias. Later `treeCondStrategy#outerTest`
// generates an outer test based on `patType.prefix` with automatically dealises.
patType.dealias match {
case tref @ TypeRef(pre, name) =>
(pre ne NoPrefix) && tref.symbol.isClass &&
ExplicitOuter.needsOuterIfReferenced(tref.symbol.asClass)
expectedTp.dealias match {
case tref @ TypeRef(pre: SingletonType, name) =>
val s = tref
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the added definition of s. Just use tref!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

variables defined in pattern matches are rarely debuggable when compiled by scalac.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, if you prefer.

s.symbol.isClass &&
ExplicitOuter.needsOuterIfReferenced(s.symbol.asClass)
case _ =>
false
}
}

override lazy val introducedRebindings = NoRebindings

def outerTestNeeded = {
val np = expectedTp.normalizedPrefix
val ts = np.termSymbol
(ts ne NoSymbol) && needsOuterTest(expectedTp, testedBinder.info, ctx.owner)
}

// the logic to generate the run-time test that follows from the fact that
// a `prevBinder` is expected to have type `expectedTp`
// the actual tree-generation logic is factored out, since the analyses generate Cond(ition)s rather than Trees
Expand Down
14 changes: 4 additions & 10 deletions compiler/src/dotty/tools/io/ClassPath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -240,22 +240,16 @@ abstract class ClassPath {
def findClass(name: String): Option[AnyClassRep] =
name.splitWhere(_ == '.', doDropIndex = true) match {
case Some((pkg, rest)) =>
val rep = packages find (_.name == pkg) flatMap (_ findClass rest)
rep map {
case x: ClassRep => x
case x => throw new FatalError("Unexpected ClassRep '%s' found searching for name '%s'".format(x, name))
}
packages find (_.name == pkg) flatMap (_ findClass rest)
case _ =>
classes find (_.name == name)
}

def findSourceFile(name: String): Option[AbstractFile] =
findClass(name) match {
case Some(ClassRep(Some(x: AbstractFile), _)) => Some(x)
case _ => None
}
def findBinaryFile(name: String): Option[AbstractFile] =
findClass(name).flatMap(_.binary)

def sortString = join(split(asClasspathString).sorted: _*)

override def equals(that: Any) = that match {
case x: ClassPath => this.sortString == x.sortString
case _ => false
Expand Down
37 changes: 37 additions & 0 deletions tests/run/i2156.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
class Outer {

case class Inner()

val inner: Inner = new Inner

def checkInstance(o: Outer) =
o.inner.isInstanceOf[this.Inner]

def checkPattern1(i: Any) =
i match {
case _: Inner => true
case _ => false
}

def checkPattern2(i: Any) =
i match {
case Inner() => true
case _ => false
}

def checkEquals(o: Outer) =
o.inner == inner
}

object Test {

def main(args: Array[String]) = {
val o1 = new Outer
val o2 = new Outer
assert(o1.checkInstance(o2)) // ok
assert(!o1.checkPattern1(o2.inner)) // ok under scalac, fails for dotc-compiled code
assert(!o1.checkPattern2(o2.inner)) // ok under scalac, fails for dotc-compiled code
assert(!o1.checkEquals(o2)) // ok under scalac, fails for dotc-compiled code
}
}