Skip to content

Commit

Permalink
Merge pull request #335 from sjrd/fix-signature-name-of-nothing
Browse files Browse the repository at this point in the history
Fix #334: Make the signatureName of Nothing be `scala.Nothing`.
  • Loading branch information
sjrd authored Aug 4, 2023
2 parents b72847c + 9a3638d commit 713d2f8
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
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 @@ -71,6 +71,7 @@ object Names {
val scalaPackageName: SimpleName = termName("scala")
val javaPackageName: SimpleName = termName("java")
val langPackageName: SimpleName = termName("lang")
val runtimePackageName: SimpleName = termName("runtime")

val EmptyTuple: SimpleName = termName("EmptyTuple")

Expand Down Expand Up @@ -131,6 +132,8 @@ object Names {

val scala2PackageObjectClass: TypeName = termName("package").withObjectSuffix.toTypeName

private[tastyquery] val runtimeNothing: TypeName = typeName("Nothing$")

private[tastyquery] val internalRepeatedAnnot: TypeName = typeName("Repeated")

private[tastyquery] val scala2LocalChild: TypeName = typeName("<local child>")
Expand Down Expand Up @@ -345,6 +348,7 @@ object Names {
val emptyPackageName = FullyQualifiedName(nme.EmptyPackageName :: Nil)
val scalaPackageName = FullyQualifiedName(nme.scalaPackageName :: Nil)
val javaLangPackageName = FullyQualifiedName(nme.javaPackageName :: nme.langPackageName :: Nil)
val scalaRuntimePackageName = FullyQualifiedName(nme.scalaPackageName :: nme.runtimePackageName :: Nil)

private[tastyquery] val scalaAnnotationInternalPackage =
FullyQualifiedName(nme.scalaPackageName :: termName("annotation") :: termName("internal") :: Nil)
Expand Down
5 changes: 4 additions & 1 deletion tasty-query/shared/src/main/scala/tastyquery/Symbols.scala
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,10 @@ object Symbols {
private[tastyquery] final def signatureName: FullyQualifiedName =
def computeErasedName(owner: Symbol, name: TypeName): FullyQualifiedName = owner match
case owner: PackageSymbol =>
owner.fullName.select(name)
val ownerFullName = owner.fullName
if name == tpnme.runtimeNothing && ownerFullName == FullyQualifiedName.scalaRuntimePackageName then
FullyQualifiedName(nme.scalaPackageName :: tpnme.Nothing :: Nil)
else ownerFullName.select(name)

case owner: ClassSymbol =>
owner.signatureName.mapLast(_.toTermName).select(name)
Expand Down
16 changes: 13 additions & 3 deletions tasty-query/shared/src/test/scala/tastyquery/TypeSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,11 @@ class TypeSuite extends UnrestrictedUnpicklingSuite {
assert(clue(parentClasses) == List(defn.ObjectClass, ProductClass, SerializableClass))
}

def applyOverloadedTest(name: String)(callMethod: String, checkParamType: Context ?=> Type => Boolean): Unit =
def applyOverloadedTest(name: String)(
callMethod: String,
checkParamType: Context ?=> Type => Boolean,
checkResultType: Context ?=> TermType => Boolean = _.isRef(defn.UnitClass)
): Unit =
testWithContext(name) {
val OverloadedApplyClass = ctx.findTopLevelClass("simple_trees.OverloadedApply")

Expand All @@ -185,10 +189,10 @@ class TypeSuite extends UnrestrictedUnpicklingSuite {
tree match
case app @ Apply(fooRef @ Select(_, SignedName(SimpleName("foo"), _, _)), _) =>
callCount += 1
assert(app.tpe.isRef(defn.UnitClass), clue(app))
assert(checkResultType(app.tpe), clue(app))
val fooSym = fooRef.tpe.asInstanceOf[TermRef].symbol
val mt = fooSym.declaredType.asInstanceOf[MethodType]
assert(clue(mt.resultType).isRef(defn.UnitClass))
assert(checkResultType(clue(mt.resultType)))
assert(checkParamType(clue(mt.paramTypes.head)))
case _ => ()
}
Expand Down Expand Up @@ -226,6 +230,12 @@ class TypeSuite extends UnrestrictedUnpicklingSuite {
List(_.isRef(defn.IntClass))
)
)
applyOverloadedTest("apply-overloaded-nothing")("callH", _.isRef(defn.StringClass), _.isType(_.isExactlyNothing))
applyOverloadedTest("apply-overloaded-null")(
"callI",
_.isRef(ctx.findTopLevelClass("java.lang.CharSequence")),
_.isRef(defn.NullClass)
)

testWithContext("apply-overloaded-not-method") {
val OverloadedApplyClass = ctx.findTopLevelClass("simple_trees.OverloadedApply")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class OverloadedApply {
def foo(a: Array[Foo.type]): Unit = ()
def foo(a: => Num): Unit = ()
def foo: String = "foo"
def foo(a: java.lang.String): Nothing = ???
def foo(a: CharSequence): Null = null

@targetName("bar") def foo(a: Box[Int]): Unit = ()

Expand All @@ -28,5 +30,7 @@ class OverloadedApply {
def callE = foo(Num())
def callF = foo
def callG = foo(Box(3))
def callH = foo("hello")
def callI = foo("hello": CharSequence)

}

0 comments on commit 713d2f8

Please sign in to comment.