Skip to content

Fix #11307 - look up definitions in packages as well #11791

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 2 commits into from
Mar 19, 2021
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
3 changes: 1 addition & 2 deletions scaladoc-testcases/src/tests/package.scala
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/** This should be moved to its own project */
package object tests {

val foo = "foo"
}
2 changes: 2 additions & 0 deletions scaladoc-testcases/src/tests/tests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ package inner {
}
}

val bar = "bar"

/** A class with a semi-non-trivial constructor.
*
* @param a Hello!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,27 +128,26 @@ trait MemberLookup {
// val syms0 = syms.toList
// val matched0 = syms0.filter(matches)
// if matched0.isEmpty then
// println(s"Failed to look up $q in $owner; all members below:")
// println(s"Failed to look up $q in $owner; all members: {{{")
// syms0.foreach { s => println(s"\t$s") }
// println("}}}")
// val matched = matched0.iterator

// def showMatched() = matched.foreach { s =>
// println(s">>> $s")
// println(s">>> ${s.pos}")
// println(s">>> [${s.flags.show}]")
// println(s">>> {${if s.isTerm then "isterm" else ""};${if s.isType then "istype" else ""}}")
// println(s">>> moduleClass = ${if hackResolveModule(s) == s then hackResolveModule(s).show else "none"}")
// def showMatched() = matched0.foreach { s =>
// println(s"\t $s")
// }
// println(s"localLookup in class ${owner} for `$q`{forceTerm=$forceTerm}")
// println(s"\t${matched0.mkString(", ")}")
// println(s"localLookup in class ${owner} for `$q`{forceTerm=$forceTerm}:")
// showMatched()

val matched = syms.filter(matches)
matched.map(hackResolveModule)
}

if owner.isPackageDef then
findMatch(hackMembersOf(owner))
findMatch(hackMembersOf(owner).flatMap {
s =>
(if s.name.endsWith("package$") then hackMembersOf(s) else Iterator.empty) ++ Iterator(s)
})
else
owner.tree match {
case tree: ClassDef =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ class LookupTestCases[Q <: Quotes](val q: Quotes) {
"Predef.identity" -> cls("scala.Predef$").fun("identity"),
"Array$.from" -> cls("scala.Array$").fun("from"),
"???" -> cls("scala.Predef$").fun("???"),
"scala.List" -> cls("scala.package$").tpe("List"),

"tests.A" -> cls("tests.A"),
"tests.A$" -> cls("tests.A$"),
"tests.Methods.simple" -> cls("tests.Methods").fun("simple"),
"tests.foo" -> cls("tests.package$").fld("foo"),
"tests.bar" -> cls("tests.tests$package$").fld("bar"),

"java.util.AbstractCollection" -> cls("java.util.AbstractCollection"),
"java.lang.String" -> cls("java.lang.String"),
Expand Down Expand Up @@ -86,6 +90,11 @@ class LookupTestCases[Q <: Quotes](val q: Quotes) {
cls("tests.A") -> "A.foo" -> cls("tests.A$").fun("foo"),

cls("tests.inner.B") -> "A" -> cls("tests.inner.A$"),

cls("tests.D") -> "foo" -> cls("tests.package$").fld("foo"),
cls("tests.D") -> "bar" -> cls("tests.tests$package$").fld("bar"),
cls("tests.inner.A$") -> "foo" -> cls("tests.package$").fld("foo"),
cls("tests.inner.A$") -> "bar" -> cls("tests.tests$package$").fld("bar"),
)

cases.foreach { case ((Sym(owner), query), Sym(target)) =>
Expand Down