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.
This adds inline accessors for private/protected members if needed as we do with inline defs. Fixes scala#8208 Fixes scala#12948
- Loading branch information
1 parent
c53cc91
commit 0d23351
Showing
6 changed files
with
43 additions
and
2 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
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,9 @@ | ||
package mylib | ||
import scala.quoted.* | ||
|
||
object Main: | ||
protected def foo: Unit = {} | ||
inline def fooCaller: Unit = foo | ||
inline def fooCallerM: Unit = ${ fooMacro } | ||
def fooMacro(using Quotes): Expr[Unit] = | ||
'{ foo } |
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 @@ | ||
import mylib.Main | ||
|
||
object Test: | ||
Main.fooCaller | ||
Main.fooCallerM |
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,22 @@ | ||
package playground | ||
|
||
import scala.quoted._ | ||
|
||
object X { | ||
|
||
inline def power(n: Int, x: Double): Double = | ||
${ powerImpl('n, 'x) } | ||
|
||
private def powerImpl(nExpr: Expr[Int], xExpr: Expr[Double])(using Quotes): Expr[Double] = | ||
nExpr match { | ||
case Expr(n1) => '{ 42.0 } | ||
case _ => '{ dynamicPower($nExpr, $xExpr) } | ||
} | ||
|
||
private def dynamicPower(n: Int, x: Double): Double = { | ||
println(s"dynamic: $n^$x") | ||
if (n == 0) 1.0 | ||
else if (n % 2 == 0) dynamicPower(n / 2, x * x) | ||
else x * dynamicPower(n - 1, x) | ||
} | ||
} |
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,2 @@ | ||
import playground.X | ||
def test(x: Int) = X.power(x, 2) |