forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
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
834882b
commit fea241b
Showing
7 changed files
with
51 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,8 @@ | ||
import scala.quoted.* | ||
|
||
package foo { | ||
trait Bar: | ||
def bar(using Quotes) = '{ Baz } | ||
|
||
private[foo] object Baz | ||
} |
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) |