-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix #2156 #2158
Changes from 5 commits
88bac0e
c5031a7
e901310
8a0c3c4
03f1304
f370799
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Code compiled by
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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:
|
||
} | ||
case _ => | ||
classes find (_.name == name) | ||
|
@@ -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 | ||
|
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 | ||
} | ||
} | ||
|
There was a problem hiding this comment.
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 usetref
!There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, if you prefer.