Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions compiler/src/dotty/tools/dotc/core/NameOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,17 @@ object NameOps {
}
}

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

private def functionSuffixStart: Int =
val first = name.firstPart
Expand Down
7 changes: 4 additions & 3 deletions compiler/src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1350,11 +1350,12 @@ trait Checking {

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

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

cls.info.decls.foreach(checkDecl)
cls.info match
Expand Down
13 changes: 13 additions & 0 deletions tests/neg/i19274.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import annotation.*

case class StaticBinding(v: String) {
private def copy$default$1(): String = ??? // error
}

case class DynamicBinding(v: String):
@targetName("copy$default$1")
private def dynamo(): String = ??? // TODO

@main def Demo =
val b = StaticBinding("test")
println(b)
13 changes: 13 additions & 0 deletions tests/pos/i19274.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//> using options -Ycheck:mixin

object Diagnostic:
trait OriginWarning(val origin: String):
self: Warning =>
object OriginWarning:
val NoOrigin = "..."

class LintWarning(msg: String, origin: String = OriginWarning.NoOrigin)
extends Warning(msg), OriginWarning(origin)

class Warning(msg: String) extends Diagnostic(msg)
class Diagnostic(val msg: String)
Loading