Skip to content

Commit ea35b01

Browse files
committed
[WIP] SIP-23 equality test for singleton type <:< AnyVal
test case: ``` val y: 5 = 5 def g(x: Int) = x match { case _: y.type => 0 } ```
1 parent 3f8b466 commit ea35b01

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/compiler/scala/tools/nsc/transform/patmat/MatchTreeMaking.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,10 @@ trait MatchTreeMaking extends MatchCodeGen with Debugging {
447447
// - Scala's arrays are invariant (so we don't drop type tests unsoundly)
448448
if (extractorArgTypeTest) mkDefault
449449
else expectedTp match {
450-
case SingleType(_, sym) => mkEqTest(gen.mkAttributedQualifier(expectedTp)) // SI-4577, SI-4897
450+
case SingleType(_, sym) =>
451+
val expected = gen.mkAttributedQualifier(expectedTp)
452+
if (expectedTp <:< AnyRefTpe) mkEqTest(expected) // SI-4577, SI-4897
453+
else mkEqualsTest(expected)
451454
// TODO SIP-23: should we test equality for literal types with eq?
452455
// Conceptually cleaner, as SingleType is tested using eq.
453456
// In practice it doesn't really matter, since `equals` does the same thing as `eq` in the `AnyVal` subclasses of `Any`.

0 commit comments

Comments
 (0)