Skip to content

Commit f7f742b

Browse files
committed
Make more types have safe equality.
1 parent 37b6283 commit f7f742b

14 files changed

+18
-17
lines changed

src/dotty/tools/dotc/ast/Positioned.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import util.DotClass
66

77
/** A base class for things that have positions (currently: modifiers and trees)
88
*/
9-
abstract class Positioned extends DotClass with Product {
9+
abstract class Positioned extends DotClass with Product with EqClass[Positioned] {
1010

1111
private[this] var curPos: Position = _
1212

src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
3232
def defKind(tree: Tree): FlagSet = unsplice(tree) match {
3333
case EmptyTree | _: Import => NoInitsInterface
3434
case tree: TypeDef => if (tree.isClassDef) NoInits else NoInitsInterface
35-
case tree: DefDef => if (tree.unforcedRhs == EmptyTree) NoInitsInterface else NoInits
36-
case tree: ValDef => if (tree.unforcedRhs == EmptyTree) NoInitsInterface else EmptyFlags
35+
case tree: DefDef => if (tree.unforcedRhs eq EmptyTree) NoInitsInterface else NoInits
36+
case tree: ValDef => if (tree.unforcedRhs eq EmptyTree) NoInitsInterface else EmptyFlags
3737
case _ => EmptyFlags
3838
}
3939

@@ -254,7 +254,7 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
254254
*/
255255
def lacksDefinition(mdef: MemberDef)(implicit ctx: Context) = mdef match {
256256
case mdef: ValOrDefDef =>
257-
mdef.unforcedRhs == EmptyTree && !mdef.name.isConstructorName && !mdef.mods.is(ParamAccessor)
257+
(mdef.unforcedRhs eq EmptyTree) && !mdef.name.isConstructorName && !mdef.mods.is(ParamAccessor)
258258
case mdef: TypeDef =>
259259
mdef.rhs.isEmpty || mdef.rhs.isInstanceOf[TypeBoundsTree]
260260
case _ => false

src/dotty/tools/dotc/core/Annotations.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import dotty.tools.dotc.ast.{tpd, untpd}
88

99
object Annotations {
1010

11-
abstract class Annotation {
11+
abstract class Annotation extends EqClass[Annotation] {
1212
def tree(implicit ctx: Context): Tree
1313
def symbol(implicit ctx: Context): Symbol =
1414
if (tree.symbol.isConstructor) tree.symbol.owner

src/dotty/tools/dotc/core/Constants.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ object Constants {
2222
// For supporting java enumerations inside java annotations (see ClassfileParser)
2323
final val EnumTag = 13
2424

25-
case class Constant(value: Any) extends printing.Showable {
25+
case class Constant(value: Any) extends printing.Showable with EqClass[Constant] {
2626
import java.lang.Double.doubleToRawLongBits
2727
import java.lang.Float.floatToRawIntBits
2828

src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,8 @@ object Contexts {
6060
with SymDenotations
6161
with Reporting
6262
with NamerContextOps
63-
with Cloneable { thiscontext =>
63+
with Cloneable
64+
with EqClass[Context] { thiscontext =>
6465
implicit def ctx: Context = this
6566

6667
/** The context base at the root */

src/dotty/tools/dotc/core/Flags.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ object Flags {
1212
* that has the intersection of the applicability to terms/types
1313
* of the two flag sets. It is checked that the intersection is not empty.
1414
*/
15-
case class FlagSet(val bits: Long) extends AnyVal {
15+
case class FlagSet(val bits: Long) extends AnyVal with EqClass[FlagSet] {
1616

1717
/** The union of this flag set and the given flag set
1818
*/
@@ -121,7 +121,7 @@ object Flags {
121121
* conjunctively. I.e. for a flag conjunction `fc`,
122122
* `x is fc` tests whether `x` contains all flags in `fc`.
123123
*/
124-
case class FlagConjunction(bits: Long) {
124+
case class FlagConjunction(bits: Long) extends EqClass[FlagConjunction] {
125125
override def toString = FlagSet(bits).toString
126126
}
127127

src/dotty/tools/dotc/core/Mode.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package dotty.tools.dotc.core
22

33
/** A collection of mode bits that are part of a context */
4-
case class Mode(val bits: Int) extends AnyVal {
4+
case class Mode(val bits: Int) extends AnyVal with EqClass[Mode] {
55
import Mode._
66
def | (that: Mode) = Mode(bits | that.bits)
77
def & (that: Mode) = Mode(bits & that.bits)

src/dotty/tools/dotc/core/Periods.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ object Periods {
5252
*
5353
* // Dmitry: sign == 0 isn't actually always true, in some cases phaseId == -1 is used for shifts, that easily creates code < 0
5454
*/
55-
class Period(val code: Int) extends AnyVal {
55+
class Period(val code: Int) extends AnyVal with EqClass[Period] {
5656

5757
/** The run identifier of this period. */
5858
def runId: RunId = code >>> (PhaseWidth * 2)

src/dotty/tools/dotc/core/Phases.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ object Phases {
261261
def isAfterTyper(phase: Phase): Boolean = phase.id > typerPhase.id
262262
}
263263

264-
trait Phase extends DotClass {
264+
trait Phase extends DotClass with EqClass[Phase] {
265265

266266
def phaseName: String
267267

src/dotty/tools/dotc/core/Signature.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import TypeErasure.sigName
2323
*
2424
* The signatures of non-method types are always `NotAMethod`.
2525
*/
26-
case class Signature(paramsSig: List[TypeName], resSig: TypeName) {
26+
case class Signature(paramsSig: List[TypeName], resSig: TypeName) extends EqClass[Signature] {
2727
import Signature._
2828

2929
/** Does this signature coincide with that signature on their parameter parts? */

src/dotty/tools/dotc/core/TyperState.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import printing.Texts._
1212
import config.Config
1313
import collection.mutable
1414

15-
class TyperState(r: Reporter) extends DotClass with Showable {
15+
class TyperState(r: Reporter) extends DotClass with Showable with EqClass[TyperState] {
1616

1717
/** The current reporter */
1818
def reporter = r

src/dotty/tools/dotc/util/Positions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ object Positions {
3030
* is roughly where the ^ would go if an error was diagnosed at that position.
3131
* All quantities are encoded opaquely in a Long.
3232
*/
33-
class Position(val coords: Long) extends AnyVal {
33+
class Position(val coords: Long) extends AnyVal with EqClass[Position] {
3434

3535
/** Is this position different from NoPosition? */
3636
def exists = this != NoPosition

src/dotty/tools/dotc/util/SourceFile.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ object ScriptSourceFile {
3434
}
3535
}
3636

37-
case class SourceFile(file: AbstractFile, content: Array[Char]) extends interfaces.SourceFile {
37+
case class SourceFile(file: AbstractFile, content: Array[Char]) extends interfaces.SourceFile with EqClass[SourceFile] {
3838

3939
def this(_file: AbstractFile) = this(_file, _file.toCharArray)
4040
def this(sourceName: String, cs: Seq[Char]) = this(new VirtualFile(sourceName), cs.toArray)

src/dotty/tools/dotc/util/SourcePosition.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package util
55
import Positions.{Position, NoPosition}
66

77
/** A source position is comprised of a position in a source file */
8-
case class SourcePosition(source: SourceFile, pos: Position) extends interfaces.SourcePosition {
8+
case class SourcePosition(source: SourceFile, pos: Position) extends interfaces.SourcePosition with EqClass[SourcePosition] {
99
def exists = pos.exists
1010

1111
def lineContent: String = source.lineContent(point)

0 commit comments

Comments
 (0)