scalacenter / tasty-query

Apache License 2.0
51 stars 11 forks source link

Fix #398: Include inherited members in the PackageRef fallback lookup. #400

Closed sjrd closed 10 months ago

sjrd commented 10 months ago

If we have a package object that extends other classes, we may have to look member selections among inherited members. This is done by getMember instead of getDecl.

To test this, we need a Scala 2 package object with an extends clause. There is no such thing in the standard library, which is our only source of Scala 2 code, unfortunately. So we don't add a test for that.


Locally, given the following dependency in the testSources:

libraryDependencies += "com.softwaremill.sttp.client" % "core_2.13" % "2.0.4",

the following TypeSuite test used to fail before, and now works:

  testWithContext("test") {
    import Signatures.*

    val sttpClientPackage = ctx.findPackage("sttp.client")
    val UriContextName = termName("UriContext")
    val UriInterpolatorClass = ctx.findTopLevelClass("sttp.model.UriInterpolator")
    val UriContextClass = UriInterpolatorClass.findDecl(typeName("UriContext")).asClass
    val StringContextClass = ctx.findTopLevelClass("scala.StringContext")

    val sig = Signature(List(ParamSig.Term(StringContextClass.signatureName)), UriContextClass.signatureName)
    val signedName = SignedName(UriContextName, sig)
    println(signedName)
    val tpRef = TermRef(sttpClientPackage.packageRef, signedName)
    val sym = tpRef.symbol
    println(sym)
    val tpe = tpRef.underlyingOrMethodic
    println(tpe.showBasic)
  }