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
Changes from 1 commit
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
5 changes: 3 additions & 2 deletions compiler/src/dotty/tools/io/ClassPath.scala
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,8 @@ abstract class ClassPath {
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))
case x: AnyClassRep => x
case x => throw new FatalError("Unexpected ClassRep '%s' found searching for name '%s'".format(x, name))
Copy link
Member

Choose a reason for hiding this comment

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

rep is an AnyClassRep so this case will never happen. I believe the original code intended to check the outer pointer, though I have no idea why, here's the commit that introduced the check: scala/scala@a1a6ab9

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Code compiled by scalac doesn't contain the check:

option = rep.map((Function1)new Serializable(this, name){
                public static final long serialVersionUID = 0;
                private final String name$2;

                public final ClassRep apply(ClassRep x0$1) {
                    ClassRep classRep = x0$1;
                    if (classRep instanceof ClassRep) {
                        ClassRep classRep2;
                        ClassRep classRep3 = classRep2 = classRep;
                        return classRep3;
                    }
                    throw new dotty.tools.FatalError(new scala.collection.immutable.StringOps(Predef..MODULE$.augmentString("Unexpected ClassRep '%s' found searching for name '%s'")).format((Seq)Predef..MODULE$.genericWrapArray((Object)new Object[]{classRep, this.name$2})));
                }

                public final /* bridge */ /* synthetic */ Object apply(Object v1) {
                    return this.apply((ClassRep)v1);
                }
            });

Copy link
Member

Choose a reason for hiding this comment

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

I'm not saying that the check was actually performed, I'm saying that the code was written assuming that the check would be performed, which apparently it wasn't.

Copy link
Contributor

@odersky odersky Mar 31, 2017

Choose a reason for hiding this comment

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

See comment on the ticket #2156. I think it's a bug in scalac. By guess is that it checks whether the test would be redundant (which is reasonable) but gets that logic messed up. For instance, here is a situation where the test should be omitted:

class Outer {
  trait Base
  class Inner extends Base

  val x: Base = ???
  x match {
    case x: Inner => ???
  }
}

}
case _ =>
classes find (_.name == name)
Expand All @@ -256,6 +256,7 @@ abstract class ClassPath {
}

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

override def equals(that: Any) = that match {
case x: ClassPath => this.sortString == x.sortString
case _ => false
Expand Down