From f06a4313fc031c85b091bf08e92a1e83fd3e46d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Tue, 10 Oct 2023 16:47:25 +0200 Subject: [PATCH] Add more tests about the erasure of Unit itself. Outside of arrays or union types. --- .../scala/tastyquery/SignatureSuite.scala | 22 +++++++++++++++++++ .../main/scala/simple_trees/UnitErasure.scala | 22 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 test-sources/src/main/scala/simple_trees/UnitErasure.scala diff --git a/tasty-query/shared/src/test/scala/tastyquery/SignatureSuite.scala b/tasty-query/shared/src/test/scala/tastyquery/SignatureSuite.scala index 26958471..6e65dd9d 100644 --- a/tasty-query/shared/src/test/scala/tastyquery/SignatureSuite.scala +++ b/tasty-query/shared/src/test/scala/tastyquery/SignatureSuite.scala @@ -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") diff --git a/test-sources/src/main/scala/simple_trees/UnitErasure.scala b/test-sources/src/main/scala/simple_trees/UnitErasure.scala new file mode 100644 index 00000000..2d8836a1 --- /dev/null +++ b/test-sources/src/main/scala/simple_trees/UnitErasure.scala @@ -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