Skip to content

Commit df88ca5

Browse files
committed
Streamline targetName matching tests
1 parent 146ef21 commit df88ca5

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

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

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ object Denotations {
352352
*/
353353
def matchingDenotation(site: Type, targetType: Type, targetName: Name)(using Context): SingleDenotation = {
354354
def qualifies(sym: Symbol) =
355-
site.memberInfo(sym).matchesLoosely(targetType) && targetNamesMatch(sym.targetName, targetName)
355+
site.memberInfo(sym).matchesLoosely(targetType) && sym.hasTargetName(targetName)
356356
if (isOverloaded)
357357
atSignature(targetType.signature, targetName, site, relaxed = true) match {
358358
case sd: SingleDenotation => sd.matchingDenotation(site, targetType, targetName)
@@ -624,8 +624,7 @@ object Denotations {
624624
relaxed
625625
case noMatch =>
626626
false
627-
if sigMatches && targetNamesMatch(symbol.targetName, targetName) then this
628-
else NoDenotation
627+
if sigMatches && symbol.hasTargetName(targetName) then this else NoDenotation
629628

630629
def matchesImportBound(bound: Type)(using Context): Boolean =
631630
if bound.isRef(defn.NothingClass) then false
@@ -986,7 +985,7 @@ object Denotations {
986985
final def last: SingleDenotation = this
987986

988987
def matches(other: SingleDenotation)(using Context): Boolean =
989-
targetNamesMatch(symbol.targetName, other.symbol.targetName)
988+
symbol.hasTargetName(other.symbol.targetName)
990989
&& {
991990
val d = signature.matchDegree(other.signature)
992991
d match
@@ -1285,7 +1284,4 @@ object Denotations {
12851284
util.Stats.record("stale symbol")
12861285
override def getMessage(): String = msg
12871286
}
1288-
1289-
def targetNamesMatch(name1: Name, name2: Name): Boolean =
1290-
name1 == name2 || name1.isEmpty || name2.isEmpty
12911287
}

compiler/src/dotty/tools/dotc/core/NameOps.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ object NameOps {
170170
}
171171
}
172172

173+
/** Do two target names match? An empty target name matchws any other name. */
174+
def matchesTargetName(other: Name) =
175+
name == other || name.isEmpty || other.isEmpty
176+
173177
private def functionSuffixStart: Int =
174178
val first = name.firstPart
175179
var idx = first.length - 1

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,9 @@ object SymDenotations {
512512
def setTargetName(name: Name): Unit =
513513
myTargetName = name
514514

515+
def hasTargetName(name: Name)(using Context): Boolean =
516+
targetName.matchesTargetName(name)
517+
515518
/** The name given in a `@targetName` annotation if one is present, `name` otherwise */
516519
def targetName(using Context): Name =
517520
if myTargetName == null then

compiler/src/dotty/tools/dotc/core/tasty/NameBuffer.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import TastyBuffer._
99
import collection.mutable
1010
import Names.{Name, chrs, SimpleName, DerivedName, TypeName}
1111
import NameKinds._
12+
import NameOps._
1213
import Decorators._
1314
import scala.io.Codec
14-
import Denotations.targetNamesMatch
1515
import NameTags.{SIGNED, TARGETSIGNED}
1616

1717
class NameBuffer extends TastyBuffer(10000) {
@@ -28,7 +28,7 @@ class NameBuffer extends TastyBuffer(10000) {
2828
name1 match {
2929
case SignedName(original, Signature(params, result), target) =>
3030
nameIndex(original)
31-
if !targetNamesMatch(original, target) then nameIndex(target)
31+
if !original.matchesTargetName(target) then nameIndex(target)
3232
nameIndex(result)
3333
params.foreach {
3434
case param: TypeName =>
@@ -95,7 +95,7 @@ class NameBuffer extends TastyBuffer(10000) {
9595
writeByte(tag)
9696
withLength { writeNameRef(original); writeNat(num) }
9797
case SignedName(original, Signature(paramsSig, result), target) =>
98-
val needsTarget = !targetNamesMatch(original, target)
98+
val needsTarget = !original.matchesTargetName(target)
9999
writeByte(if needsTarget then TARGETSIGNED else SIGNED)
100100
withLength(
101101
{ writeNameRef(original)

compiler/src/dotty/tools/dotc/reporting/messages.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ import transform.SymUtils._
10861086
extends DeclarationMsg(OverridesNothingButNameExistsID) {
10871087
def msg =
10881088
val what =
1089-
if !existing.exists(sd => Denotations.targetNamesMatch(member.targetName, sd.symbol.targetName))
1089+
if !existing.exists(_.symbol.hasTargetName(member.targetName))
10901090
then "target name"
10911091
else "signature"
10921092
em"""${member} has a different $what than the overridden declaration"""

0 commit comments

Comments
 (0)