Skip to content

Commit 01d038c

Browse files
committed
Overcome Name comparison hurdles
1 parent 4247597 commit 01d038c

File tree

4 files changed

+40
-5
lines changed

4 files changed

+40
-5
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,17 @@ object NameOps {
188188
}
189189
}
190190

191-
/** Do two target names match? An empty target name matchws any other name. */
191+
/** Do two target names match? An empty target name matches any other name.
192+
* Target names match if their simple names compare equal,
193+
* if they belong to the same term or type namespace,
194+
* and it's not the case that only one is a field name.
195+
*/
192196
def matchesTargetName(other: Name) =
193-
name == other || name.isEmpty || other.isEmpty
197+
name.isEmpty
198+
|| other.isEmpty
199+
|| name.isTermName == other.isTermName
200+
&& name.is(NameKinds.FieldName) == other.is(NameKinds.FieldName)
201+
&& name.toSimpleName == other.toSimpleName
194202

195203
private def functionSuffixStart: Int =
196204
val first = name.firstPart

compiler/src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1350,11 +1350,12 @@ trait Checking {
13501350

13511351
/** Check that class does not declare same symbol twice */
13521352
def checkNoDoubleDeclaration(cls: Symbol)(using Context): Unit =
1353-
val seen = new mutable.HashMap[Name, List[Symbol]].withDefaultValue(Nil)
1353+
val seen = new mutable.HashMap[String, List[Symbol]].withDefaultValue(Nil)
13541354
typr.println(i"check no double declarations $cls")
13551355

13561356
def checkDecl(decl: Symbol): Unit =
1357-
for other <- seen(decl.name) if decl.name != nme.ERROR && !decl.isAbsent() && !other.isAbsent() do
1357+
val key = decl.name.toString
1358+
for other <- seen(key) if decl.name != nme.ERROR && !decl.isAbsent() && !other.isAbsent() do
13581359
typr.println(i"conflict? $decl $other")
13591360
def javaFieldMethodPair =
13601361
decl.is(JavaDefined) && other.is(JavaDefined) &&
@@ -1371,7 +1372,7 @@ trait Checking {
13711372
report.error(em"two or more overloaded variants of $decl have default arguments", decl.srcPos)
13721373
decl.resetFlag(HasDefaultParams)
13731374
if !excludeFromDoubleDeclCheck(decl) then
1374-
seen(decl.name) = decl :: seen(decl.name)
1375+
seen(key) ::= decl
13751376

13761377
cls.info.decls.foreach(checkDecl)
13771378
cls.info match

tests/neg/i19274.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import annotation.*
2+
3+
case class StaticBinding(v: String) {
4+
private def copy$default$1(): String = ??? // error
5+
}
6+
7+
case class DynamicBinding(v: String):
8+
@targetName("copy$default$1")
9+
private def dynamo(): String = ??? // TODO
10+
11+
@main def Demo =
12+
val b = StaticBinding("test")
13+
println(b)

tests/pos/i19274.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//> using options -Ycheck:mixin
2+
3+
object Diagnostic:
4+
trait OriginWarning(val origin: String):
5+
self: Warning =>
6+
object OriginWarning:
7+
val NoOrigin = "..."
8+
9+
class LintWarning(msg: String, origin: String = OriginWarning.NoOrigin)
10+
extends Warning(msg), OriginWarning(origin)
11+
12+
class Warning(msg: String) extends Diagnostic(msg)
13+
class Diagnostic(val msg: String)

0 commit comments

Comments
 (0)