Skip to content

Commit

Permalink
Add more tests about the erasure of Unit itself.
Browse files Browse the repository at this point in the history
Outside of arrays or union types.
  • Loading branch information
sjrd committed Oct 10, 2023
1 parent d9ac25b commit f06a431
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
22 changes: 22 additions & 0 deletions tasty-query/shared/src/test/scala/tastyquery/SignatureSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,28 @@ class SignatureSuite extends UnrestrictedUnpicklingSuite:
assertSigned(withArrayExactAnyVal, "(java.lang.Object[]):scala.Unit")
}

testWithContext("unit-erasure") {
val UnitErasureClass = ctx.findTopLevelClass("simple_trees.UnitErasure")

val unitVal = UnitErasureClass.findNonOverloadedDecl(termName("unitVal"))
assertNotSigned(unitVal, "():scala.Unit")

val unitVar = UnitErasureClass.findNonOverloadedDecl(termName("unitVar"))
assertNotSigned(unitVar, "():scala.Unit")

val unitVarSetter = UnitErasureClass.findNonOverloadedDecl(termName("unitVar_="))
assertSigned(unitVarSetter, "(scala.runtime.BoxedUnit):scala.Unit")

val unitParamelessDef = UnitErasureClass.findNonOverloadedDecl(termName("unitParamelessDef"))
assertNotSigned(unitParamelessDef, "():scala.Unit")

val unitResult = UnitErasureClass.findNonOverloadedDecl(termName("unitResult"))
assertSigned(unitResult, "():scala.Unit")

val unitParam = UnitErasureClass.findNonOverloadedDecl(termName("unitParam"))
assertSigned(unitParam, "(scala.runtime.BoxedUnit):java.lang.Object")
}

testWithContext("type-member") {
val TypeMember = ctx.findTopLevelClass("simple_trees.TypeMember")

Expand Down
22 changes: 22 additions & 0 deletions test-sources/src/main/scala/simple_trees/UnitErasure.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package simple_trees

class UnitErasure:
val unitVal: Unit = ()

var unitVar: Unit = ()

def unitParamelessDef: Unit = ()

def unitResult(): Unit = ()

def unitParam(x: Unit): Any = x

def calls(): Unit =
val _ = unitVal
val _ = unitVar
unitVar = ()
unitParamelessDef
unitResult()
unitParam(())
end calls
end UnitErasure

0 comments on commit f06a431

Please sign in to comment.