Skip to content

Commit 6c92dd9

Browse files
committed
Fix #2795: Fix is test on Names
The previous logic would have UniqueNames shadow everything else. So if one starts with a UniqueName(prefix, sep, number), and then does a qualified name, one gets a unique name or a qualified name. the resulting name should still be recognized as a qualified name, however. The change in this commit achieves that.
1 parent 0109fef commit 6c92dd9

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ object NameKinds {
4242
override def toString = infoString
4343
}
4444

45-
/** Does this kind define logically a new name? Tested by the `rewrite` and `collect`
46-
* combinators of names.
45+
/** Does this kind define logically a new name (respectively qualified name)?
46+
* Tested by the `rewrite` and `collect` combinators of class `Name`.
4747
*/
4848
def definesNewName = false
49+
def definesQualifiedName = false
4950

5051
/** Unmangle simple name `name` into a name of this kind, or return
5152
* original name if this is not possible.
@@ -142,6 +143,7 @@ object NameKinds {
142143
}
143144

144145
override def definesNewName = true
146+
override def definesQualifiedName = true
145147

146148
def mkString(underlying: TermName, info: ThisInfo) =
147149
s"$underlying$separator${info.name}"

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,25 @@ object Names {
233233
}
234234
}
235235

236+
/** Is it impossible that trees of kind `kind` qualify as
237+
* derived trees of kind `shadowed`?
238+
*/
239+
private def shadows(kind: NameKind, shadowed: NameKind): Boolean =
240+
kind.tag < shadowed.tag ||
241+
kind.definesQualifiedName ||
242+
kind.definesNewName && !shadowed.definesQualifiedName
243+
236244
override def exclude(kind: NameKind): TermName = {
237245
val thisKind = this.info.kind
238-
if (thisKind.tag < kind.tag || thisKind.definesNewName) this
246+
if (shadows(thisKind, kind)) this
239247
else if (thisKind.tag > kind.tag) rewrap(underlying.exclude(kind))
240248
else underlying
241249
}
242250

243251
override def is(kind: NameKind): Boolean = {
244252
val thisKind = this.info.kind
245253
thisKind == kind ||
246-
!thisKind.definesNewName && thisKind.tag > kind.tag && underlying.is(kind)
254+
!shadows(thisKind, kind) && underlying.is(kind)
247255
}
248256

249257
@sharable // because it's just a cache for performance

0 commit comments

Comments
 (0)