Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Add test cases for value class handling
  • Loading branch information
noti0na1 committed Dec 10, 2025
commit b1130ab4527d06c3f7e7783c67a92d978f717989
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/JavaPlatform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class JavaPlatform extends Platform {
// Superaccessors already show up as abstract methods here, so no test necessary
cls.typeRef.fields.isEmpty &&
// Check if the SAM can be implemented via LambdaMetaFactory
TypeErasure.samNotNeededExpansion(cls)
TypeErasure.samExpansionNotNeeded(cls)

/** We could get away with excluding BoxedBooleanClass for the
* purpose of equality testing since it need not compare equal
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ object TypeErasure:
* @param cls The SAM class to check
* @return true if LMF can handle the required adaptation
*/
def samNotNeededExpansion(cls: ClassSymbol)(using Context): Boolean = cls.typeRef.possibleSamMethods match
def samExpansionNotNeeded(cls: ClassSymbol)(using Context): Boolean = cls.typeRef.possibleSamMethods match
case Seq(samMeth) =>
val samMethSym = samMeth.symbol
val erasedSamInfo = transformInfo(samMethSym, samMeth.info)
Expand All @@ -680,7 +680,7 @@ object TypeErasure:
case _ => true
}
case _ => false
end samNotNeededExpansion
end samExpansionNotNeeded
end TypeErasure

import TypeErasure.*
Expand Down
2 changes: 2 additions & 0 deletions tests/run/i24573.check
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
22
23
24
25
31
32
33
Expand All @@ -35,6 +36,7 @@
62
63
64
65
71
72
75
Expand Down
12 changes: 12 additions & 0 deletions tests/run/i24573.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ trait ConIS extends (Int => String):
trait ConUU extends (() => Unit):
def apply(): Unit

trait ConVCVC extends (IntVal => IntVal):
def apply(t: IntVal): IntVal

trait F1[-T, +R]:
def apply(t: T): R

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

trait SFVCVC extends F1[IntVal, IntVal]:
def apply(t: IntVal): IntVal

trait F1U[-T]:
def apply(t: T): Unit

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

case class IntVal(value: Int) extends AnyVal

object Test:
def main(args: Array[String]): Unit =
val fIU: (Int => Unit) = (x: Int) => println(x) // closure by JFunction1
Expand Down Expand Up @@ -112,6 +120,8 @@ object Test:
println(conIS(23))
val conUU: ConUU = () => println("24") // expanded
conUU()
val conVCVC: ConVCVC = (x: IntVal) => IntVal(x.value + 1) // expanded
println(conVCVC(IntVal(24)).value)

val ffIU: F1[Int, Unit] = (x: Int) => println(x) // closure
ffIU(31)
Expand Down Expand Up @@ -159,6 +169,8 @@ object Test:
println(sfIS(63))
val sfIU: SFIU = (x: Int) => println(x) // expanded
sfIU(64)
val sfVCVC: SFVCVC = (x: IntVal) => IntVal(x.value + 1) // expanded
println(sfVCVC(IntVal(64)).value)

val f2ITU: F1U[Int] = (x: Int) => println(x) // closure
f2ITU(71)
Expand Down
Loading