Skip to content

Commit 605a439

Browse files
committed
Overcome Name comparison hurdles
1 parent 0bb0433 commit 605a439

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
defmatchesTargetName(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
privatedeffunctionSuffixStart:Int=
196204
valfirst= name.firstPart

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

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

13451345
/** Check that class does not declare same symbol twice */
13461346
defcheckNoDoubleDeclaration(cls: Symbol)(usingContext):Unit=
1347-
valseen=new mutable.HashMap[Name, List[Symbol]].withDefaultValue(Nil)
1347+
valseen=new mutable.HashMap[String, List[Symbol]].withDefaultValue(Nil)
13481348
typr.println(i"check no double declarations $cls")
13491349

13501350
defcheckDecl(decl: Symbol):Unit=
1351-
for other <- seen(decl.name) if decl.name != nme.ERROR&&!decl.isAbsent() &&!other.isAbsent() do
1351+
valkey= decl.name.toString
1352+
for other <- seen(key) if decl.name != nme.ERROR&&!decl.isAbsent() &&!other.isAbsent() do
13521353
typr.println(i"conflict? $decl$other")
13531354
defjavaFieldMethodPair=
13541355
decl.is(JavaDefined) && other.is(JavaDefined) &&
@@ -1365,7 +1366,7 @@ trait Checking{
13651366
report.error(em"two or more overloaded variants of $decl have default arguments", decl.srcPos)
13661367
decl.resetFlag(HasDefaultParams)
13671368
if!excludeFromDoubleDeclCheck(decl) then
1368-
seen(decl.name) = decl :: seen(decl.name)
1369+
seen(key) ::=decl
13691370

13701371
cls.info.decls.foreach(checkDecl)
13711372
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+
importannotation.*
2+
3+
caseclassStaticBinding(v: String){
4+
privatedefcopy$default$1():String=???// error
5+
}
6+
7+
caseclassDynamicBinding(v: String):
8+
@targetName("copy$default$1")
9+
privatedefdynamo():String=???// TODO
10+
11+
@main defDemo=
12+
valb=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+
//>usingoptions-Ycheck:mixin
2+
3+
objectDiagnostic:
4+
traitOriginWarning(valorigin:String):
5+
self: Warning=>
6+
objectOriginWarning:
7+
valNoOrigin="..."
8+
9+
classLintWarning(msg: String, origin: String=OriginWarning.NoOrigin)
10+
extendsWarning(msg), OriginWarning(origin)
11+
12+
classWarning(msg: String) extendsDiagnostic(msg)
13+
classDiagnostic(valmsg:String)

0 commit comments

Comments
(0)