Skip to content

Fix #2795: Fix name kind testing logic #2798

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 23, 2017
Merged
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
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/ScalaSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class ScalaSettings extends Settings.SettingGroup {
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.")
val YcheckAllPatmat = BooleanSetting("-Ycheck-all-patmat", "Check exhaustivity and redundancy of all pattern matching (used for testing the algorithm)")
val YretainTrees = BooleanSetting("-Yretain-trees", "Retain trees for top-level classes, accessible from ClassSymbol#tree")
val YshowTreeIds = BooleanSetting("-Yshow-tree-ids", "Uniquely tag all tree nodes in debugging output.")

/** Area-specific debug output */
val Yexplainlowlevel = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")
Expand Down
6 changes: 4 additions & 2 deletions compiler/src/dotty/tools/dotc/core/NameKinds.scala
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ object NameKinds {
override def toString = infoString
}

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

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

override def definesNewName = true
override def definesQualifiedName = true

def mkString(underlying: TermName, info: ThisInfo) =
s"$underlying$separator${info.name}"
Expand Down
10 changes: 8 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Names.scala
Original file line number Diff line number Diff line change
Expand Up @@ -233,17 +233,23 @@ object Names {
}
}

/** Is it impossible that names of kind `kind` also qualify as names of kind `shadowed`? */
private def shadows(kind: NameKind, shadowed: NameKind): Boolean =
kind.tag < shadowed.tag ||
kind.definesQualifiedName ||
kind.definesNewName && !shadowed.definesQualifiedName

override def exclude(kind: NameKind): TermName = {
val thisKind = this.info.kind
if (thisKind.tag < kind.tag || thisKind.definesNewName) this
if (shadows(thisKind, kind)) this
else if (thisKind.tag > kind.tag) rewrap(underlying.exclude(kind))
else underlying
}

override def is(kind: NameKind): Boolean = {
val thisKind = this.info.kind
thisKind == kind ||
!thisKind.definesNewName && thisKind.tag > kind.tag && underlying.is(kind)
!shadows(thisKind, kind) && underlying.is(kind)
}

@sharable // because it's just a cache for performance
Expand Down
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -617,6 +617,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
val clsStr = ""//if (tree.isType) tree.getClass.toString else ""
txt = (txt ~ "@" ~ pos.toString ~ clsStr).close
}
if (ctx.settings.YshowTreeIds.value)
txt = (txt ~ "#" ~ tree.uniqueId.toString).close
tree match {
case Block(_, _) | Template(_, _, _, _) => txt
case _ => txt.close
Expand Down
9 changes: 9 additions & 0 deletions tests/run/i2795.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import reflect.ClassTag

trait Foo[T: ClassTag]() {
def foo(x: T) = Array(x)
}
class Bar extends Foo[Int]()
object Test extends App {
(new Bar).foo(3)
}