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 1 commit
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
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
12 changes: 10 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,25 @@ object Names {
}
}

/** Is it impossible that trees of kind `kind` qualify as
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean names, not trees, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops. Of course.

* derived trees 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