Skip to content

Commit b1130ab

Browse files
committed
Add test cases for value class handling
1 parent 84bf3e8 commit b1130ab

File tree

4 files changed

+17
-3
lines changed

4 files changed

+17
-3
lines changed

compiler/src/dotty/tools/dotc/config/JavaPlatform.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class JavaPlatform extends Platform {
5353
// Superaccessors already show up as abstract methods here, so no test necessary
5454
cls.typeRef.fields.isEmpty &&
5555
// Check if the SAM can be implemented via LambdaMetaFactory
56-
TypeErasure.samNotNeededExpansion(cls)
56+
TypeErasure.samExpansionNotNeeded(cls)
5757

5858
/** We could get away with excluding BoxedBooleanClass for the
5959
* purpose of equality testing since it need not compare equal

compiler/src/dotty/tools/dotc/core/TypeErasure.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -661,7 +661,7 @@ object TypeErasure:
661661
* @param cls The SAM class to check
662662
* @return true if LMF can handle the required adaptation
663663
*/
664-
def samNotNeededExpansion(cls: ClassSymbol)(using Context): Boolean = cls.typeRef.possibleSamMethods match
664+
def samExpansionNotNeeded(cls: ClassSymbol)(using Context): Boolean = cls.typeRef.possibleSamMethods match
665665
case Seq(samMeth) =>
666666
val samMethSym = samMeth.symbol
667667
val erasedSamInfo = transformInfo(samMethSym, samMeth.info)
@@ -680,7 +680,7 @@ object TypeErasure:
680680
case _ => true
681681
}
682682
case _ => false
683-
end samNotNeededExpansion
683+
end samExpansionNotNeeded
684684
end TypeErasure
685685

686686
import TypeErasure.*

tests/run/i24573.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
22
1616
23
1717
24
18+
25
1819
31
1920
32
2021
33
@@ -35,6 +36,7 @@
3536
62
3637
63
3738
64
39+
65
3840
71
3941
72
4042
75

tests/run/i24573.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ trait ConIS extends (Int => String):
2828
trait ConUU extends (() => Unit):
2929
def apply(): Unit
3030

31+
trait ConVCVC extends (IntVal => IntVal):
32+
def apply(t: IntVal): IntVal
33+
3134
trait F1[-T, +R]:
3235
def apply(t: T): R
3336

@@ -58,6 +61,9 @@ trait SFIS extends F1[Int, String]:
5861
trait SFIU extends F1[Int, Unit]:
5962
def apply(t: Int): Unit
6063

64+
trait SFVCVC extends F1[IntVal, IntVal]:
65+
def apply(t: IntVal): IntVal
66+
6167
trait F1U[-T]:
6268
def apply(t: T): Unit
6369

@@ -70,6 +76,8 @@ trait SF2I extends F1U[Int]:
7076
trait SF2S extends F1U[String]:
7177
def apply(t: String): Unit
7278

79+
case class IntVal(value: Int) extends AnyVal
80+
7381
object Test:
7482
def main(args: Array[String]): Unit =
7583
val fIU: (Int => Unit) = (x: Int) => println(x) // closure by JFunction1
@@ -112,6 +120,8 @@ object Test:
112120
println(conIS(23))
113121
val conUU: ConUU = () => println("24") // expanded
114122
conUU()
123+
val conVCVC: ConVCVC = (x: IntVal) => IntVal(x.value + 1) // expanded
124+
println(conVCVC(IntVal(24)).value)
115125

116126
val ffIU: F1[Int, Unit] = (x: Int) => println(x) // closure
117127
ffIU(31)
@@ -159,6 +169,8 @@ object Test:
159169
println(sfIS(63))
160170
val sfIU: SFIU = (x: Int) => println(x) // expanded
161171
sfIU(64)
172+
val sfVCVC: SFVCVC = (x: IntVal) => IntVal(x.value + 1) // expanded
173+
println(sfVCVC(IntVal(64)).value)
162174

163175
val f2ITU: F1U[Int] = (x: Int) => println(x) // closure
164176
f2ITU(71)

0 commit comments

Comments
 (0)