forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Silence outer pointer warnings in class-based REPL
Case classes, such as final case classes nested within other classes, lose their outer pointer which makes their equality lie (scala/bug#4440): scala> class Outer { final case class Inner(n: Int) } warning: there was one unchecked warning; for details, enable `:setting -unchecked' or `:replay -unchecked' defined class Outer scala> val o1, o2 = new Outer o1: Outer = Outer@627bcd7e o2: Outer = Outer@70543cae scala> new o1.Inner(1) == new o2.Inner(1) res0: Boolean = true vs scala> class Outer { case class Inner(n: Int) } defined class Outer scala> val o1, o2 = new Outer o1: Outer = Outer@77ba583 o2: Outer = Outer@5613247e scala> new o1.Inner(1) == new o2.Inner(1) res0: Boolean = false This isn't a problem in the REPL even with its class-based wrappers as there is only ever 1 instance of (each) wrapper class.
- Loading branch information
Showing
3 changed files
with
50 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
scala> sealed abstract class Value; object Value { | ||
final case class Num(value: Double) extends Value | ||
final case class Str(value: String) extends Value | ||
final case class Bool(value: Boolean) extends Value | ||
} | ||
defined class Value | ||
defined object Value | ||
|
||
scala> class C { final case class Num(value: Double) } // here it should still warn | ||
warning: there was one unchecked warning; for details, enable `:setting -unchecked' or `:replay -unchecked' | ||
defined class C | ||
|
||
scala> :quit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import scala.tools.nsc.Settings | ||
import scala.tools.partest.ReplTest | ||
|
||
object Test extends ReplTest { | ||
override def transformSettings(s: Settings) = { | ||
s.Yreplclassbased.value = true | ||
s | ||
} | ||
|
||
def code = """ | ||
|sealed abstract class Value; object Value { | ||
| final case class Num(value: Double) extends Value | ||
| final case class Str(value: String) extends Value | ||
| final case class Bool(value: Boolean) extends Value | ||
|} | ||
|class C { final case class Num(value: Double) } // here it should still warn | ||
|""".stripMargin // scala/bug#11902 | ||
} | ||
|
||
/* was: | ||
scala> sealed abstract class Value; object Value { | ||
final case class Num(value: Double) extends Value | ||
final case class Str(value: String) extends Value | ||
final case class Bool(value: Boolean) extends Value | ||
} | ||
warning: there were three unchecked warnings; for details, enable `:setting -unchecked' or `:replay -unchecked' | ||
defined class Value | ||
defined object Value | ||
scala> class C { final case class Num(value: Double) } // here it should still warn | ||
warning: there was one unchecked warning; for details, enable `:setting -unchecked' or `:replay -unchecked' | ||
defined class C | ||
*/ |