Skip to content

Commit

Permalink
Merge pull request #156 from bishabosha/resolve-root-pkg-2
Browse files Browse the repository at this point in the history
strip _root_ from FQN in nameTable
  • Loading branch information
adpi2 authored Oct 6, 2022
2 parents 7dac288 + cf61778 commit 6fe0753
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 7 deletions.
6 changes: 1 addition & 5 deletions tasty-query/shared/src/main/scala/tastyquery/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,7 @@ object Contexts {
rec(next, pathRest)
case name :: pathRest =>
throw MemberNotFoundException(owner, name, s"cannot find package member $name of $owner")
// strip initial `_root_` if present, which is how user signals qualified from root names.
val path0 = fullyQualifiedName.path match
case nme.RootPackageName :: path => path
case path => path
rec(RootPackage, path0)
rec(RootPackage, fullyQualifiedName.path)
end findPackageFromRoot

def findSymbolFromRoot(path: List[Name]): Symbol =
Expand Down
4 changes: 4 additions & 0 deletions tasty-query/shared/src/main/scala/tastyquery/Names.scala
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,10 @@ object Names {
def mapLast(op: Name => Name): FullyQualifiedName =
FullyQualifiedName(path.init :+ op(path.last))

private[tastyquery] def sourceName: Name = path match
case Nil => nme.RootPackageName
case path => path.last

def mapLastOption(op: Name => Name): FullyQualifiedName =
if path.isEmpty then this
else mapLast(op)
Expand Down
2 changes: 1 addition & 1 deletion tasty-query/shared/src/main/scala/tastyquery/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ object Trees {

/** reference to a package, seen as a term */
final class ReferencedPackage(val fullyQualifiedName: FullyQualifiedName)(span: Span)
extends Ident(fullyQualifiedName.path.last.asSimpleName)(span) {
extends Ident(fullyQualifiedName.sourceName.asSimpleName)(span) {
protected final def calculateType(using Context): Type =
PackageRef(fullyQualifiedName)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,13 @@ private[reader] object TastyUnpickler {
def fullyQualified(ref: NameRef): FullyQualifiedName =
apply(ref) match
case name: FullyQualifiedName =>
name
name.path match
case nme.RootPackageName :: Nil =>
FullyQualifiedName.rootPackageName
case _ =>
name
case nme.RootPackageName =>
FullyQualifiedName.rootPackageName
case name: TermName =>
FullyQualifiedName(name :: Nil)
}
Expand Down

0 comments on commit 6fe0753

Please sign in to comment.