Skip to content

Commit c37f60a

Browse files
committed
Safe equality for core classes:
Name, Symbol, Denotation, Type. This uncovered two nonsensical comparisons, one in CollectEntryPoints, the other in DottyBackendInterface.
1 parent db6c132 commit c37f60a

File tree

7 files changed

+7
-7
lines changed

7 files changed

+7
-7
lines changed

src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -861,7 +861,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile)(implicit ctx: Context
861861
"If possible, please file a bug on issues.scala-lang.org.")
862862

863863
tp match {
864-
case ThisType(ArrayClass) => ObjectReference.asInstanceOf[ct.bTypes.ClassBType] // was introduced in 9b17332f11 to fix SI-999, but this code is not reached in its test, or any other test
864+
case tp: ThisType if tp.cls == ArrayClass => ObjectReference.asInstanceOf[ct.bTypes.ClassBType] // was introduced in 9b17332f11 to fix SI-999, but this code is not reached in its test, or any other test
865865
case ThisType(sym) => storage.getClassBTypeAndRegisterInnerClass(sym.asInstanceOf[ct.int.Symbol])
866866
// case t: SingletonType => primitiveOrClassToBType(t.classSymbol)
867867
case t: SingletonType => t.underlying.toTypeKind(ct)(storage)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ object Denotations {
9797
*
9898
* @param symbol The referencing symbol, or NoSymbol is none exists
9999
*/
100-
abstract class Denotation(val symbol: Symbol) extends util.DotClass with printing.Showable {
100+
abstract class Denotation(val symbol: Symbol) extends util.DotClass with printing.Showable with EqClassOf[Denotation] {
101101

102102
/** The type info of the denotation, exists only for non-overloaded denotations */
103103
def info(implicit ctx: Context): Type

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ object Names {
3535
* 3. Names are intended to be encoded strings. @see dotc.util.NameTransformer.
3636
* The encoding will be applied when converting a string to a name.
3737
*/
38-
abstract class Name extends DotClass
38+
abstract class Name extends DotClass with EqClassOf[Name]
3939
with PreName
4040
with collection.immutable.Seq[Char]
4141
with IndexedSeqOptimized[Char, Name] {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,7 @@ object SymDenotations {
509509
*/
510510
final def isSelfSym(implicit ctx: Context) = owner.infoOrCompleter match {
511511
case ClassInfo(_, _, _, _, selfInfo) =>
512-
selfInfo == symbol ||
512+
(selfInfo eq symbol) ||
513513
selfInfo.isInstanceOf[Type] && name == nme.WILDCARD
514514
case _ => false
515515
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ object Symbols {
365365
* @param coord The coordinates of the symbol (a position or an index)
366366
* @param id A unique identifier of the symbol (unique per ContextBase)
367367
*/
368-
class Symbol private[Symbols] (val coord: Coord, val id: Int) extends DotClass with printing.Showable {
368+
class Symbol private[Symbols] (val coord: Coord, val id: Int) extends DotClass with printing.Showable with EqClassOf[Symbol] {
369369

370370
type ThisName <: Name
371371

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ object Types {
7070
* +- ErrorType
7171
* +- WildcardType
7272
*/
73-
abstract class Type extends DotClass with Hashable with printing.Showable {
73+
abstract class Type extends DotClass with Hashable with printing.Showable with EqClassOf[Type] {
7474

7575
// ----- Tests -----------------------------------------------------
7676

src/dotty/tools/dotc/transform/CollectEntryPoints.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class CollectEntryPoints extends MiniPhaseTransform {
7575
val javaPlatform = ctx.platform.asInstanceOf[JavaPlatform]
7676
if (javaPlatform.hasJavaMainMethod(companion))
7777
failNoForwarder("companion contains its own main method")
78-
else if (companion != NoSymbol && companion.info.member(nme.main) != NoSymbol)
78+
else if (companion.exists && companion.info.member(nme.main).exists)
7979
// this is only because forwarders aren't smart enough yet
8080
failNoForwarder("companion contains its own main method (implementation restriction: no main is allowed, regardless of signature)")
8181
else if (companion.flags is Flags.Trait)

0 commit comments

Comments
 (0)