forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Specialized retained inline FunctionN apply methods
Fixes scala#19724
- Loading branch information
1 parent
7f410aa
commit 22020f3
Showing
3 changed files
with
44 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
object repro: | ||
abstract class Mapper[A, B] extends (A => B) | ||
|
||
given Mapper[Int, Double] with | ||
inline def apply(v: Int): Double = v.toDouble |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
class F0 extends (() => Double): | ||
inline def apply(): Double = 1.toDouble | ||
|
||
class F1 extends (Int => Double): | ||
inline def apply(v: Int): Double = v.toDouble | ||
|
||
class F2 extends ((Int, Int) => Double): | ||
inline def apply(v1: Int, v2: Int): Double = (v1 + v2).toDouble | ||
|
||
@main def Test = | ||
val f0: (() => Double) = new F0 | ||
assert(f0() == 1.0) | ||
|
||
val f1: (Int => Double) = new F1 | ||
assert(f1(3) == 3.0) | ||
|
||
val f2: ((Int, Int) => Double) = new F2 | ||
assert(f2(3, 2) == 5.0) |