Skip to content

Commit 9513ed2

Browse files
authored
Merge pull request #2798 from dotty-staging/fix-#2795
Fix #2795: Fix name kind testing logic
2 parents 76e7bb5 + 1a9d594 commit 9513ed2

File tree

5 files changed

+24
-4
lines changed

5 files changed

+24
-4
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ class ScalaSettings extends Settings.SettingGroup {
9999
val YdumpSbtInc = BooleanSetting("-Ydump-sbt-inc", "For every compiled foo.scala, output the API representation and dependencies used for sbt incremental compilation in foo.inc, implies -Yforce-sbt-phases.")
100100
val YcheckAllPatmat = BooleanSetting("-Ycheck-all-patmat", "Check exhaustivity and redundancy of all pattern matching (used for testing the algorithm)")
101101
val YretainTrees = BooleanSetting("-Yretain-trees", "Retain trees for top-level classes, accessible from ClassSymbol#tree")
102+
val YshowTreeIds = BooleanSetting("-Yshow-tree-ids", "Uniquely tag all tree nodes in debugging output.")
102103

103104
/** Area-specific debug output */
104105
val Yexplainlowlevel = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")

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: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,17 +233,23 @@ object Names {
233233
}
234234
}
235235

236+
/** Is it impossible that names of kind `kind` also qualify as names of kind `shadowed`? */
237+
private def shadows(kind: NameKind, shadowed: NameKind): Boolean =
238+
kind.tag < shadowed.tag ||
239+
kind.definesQualifiedName ||
240+
kind.definesNewName && !shadowed.definesQualifiedName
241+
236242
override def exclude(kind: NameKind): TermName = {
237243
val thisKind = this.info.kind
238-
if (thisKind.tag < kind.tag || thisKind.definesNewName) this
244+
if (shadows(thisKind, kind)) this
239245
else if (thisKind.tag > kind.tag) rewrap(underlying.exclude(kind))
240246
else underlying
241247
}
242248

243249
override def is(kind: NameKind): Boolean = {
244250
val thisKind = this.info.kind
245251
thisKind == kind ||
246-
!thisKind.definesNewName && thisKind.tag > kind.tag && underlying.is(kind)
252+
!shadows(thisKind, kind) && underlying.is(kind)
247253
}
248254

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

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
617617
val clsStr = ""//if (tree.isType) tree.getClass.toString else ""
618618
txt = (txt ~ "@" ~ pos.toString ~ clsStr).close
619619
}
620+
if (ctx.settings.YshowTreeIds.value)
621+
txt = (txt ~ "#" ~ tree.uniqueId.toString).close
620622
tree match {
621623
case Block(_, _) | Template(_, _, _, _) => txt
622624
case _ => txt.close

tests/run/i2795.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import reflect.ClassTag
2+
3+
trait Foo[T: ClassTag]() {
4+
def foo(x: T) = Array(x)
5+
}
6+
class Bar extends Foo[Int]()
7+
object Test extends App {
8+
(new Bar).foo(3)
9+
}

0 commit comments

Comments
 (0)