-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64996f4
commit ffd8f5a
Showing
4 changed files
with
54 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package examples.select | ||
|
||
import scala.language.dynamics | ||
import scala.quoted.* | ||
|
||
case class Wrapper[A](inner: A) extends Dynamic: | ||
transparent inline def selectDynamic(inline name: String) = | ||
${selectDynamicImpl('inner, 'name)} | ||
|
||
def selectDynamicImpl[A:Type](inner: Expr[A], name: Expr[String])(using quotes: Quotes): Expr[Any] = | ||
import quotes.reflect.* | ||
Select.unique(inner.asTerm, name.valueOrAbort).asExpr |
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,15 @@ | ||
package examples.select | ||
|
||
|
||
import scala.language.dynamics | ||
import examples.select.Wrapper | ||
|
||
object Dynamic0: | ||
|
||
@main | ||
def runTimeError = | ||
|
||
val w = Wrapper(Option(1)) | ||
println(w.isEmpty) | ||
|
||
end Dynamic0 |
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,12 @@ | ||
package examples.select | ||
|
||
import scala.language.dynamics | ||
import scala.quoted.* | ||
|
||
case class Wrapper[A](inner: A) extends Dynamic: | ||
transparent inline def selectDynamic(inline name: String) = | ||
${selectDynamicImpl('inner, 'name)} | ||
|
||
def selectDynamicImpl[A:Type](inner: Expr[A], name: Expr[String])(using quotes: Quotes): Expr[Any] = | ||
import quotes.reflect.* | ||
Select.unique(inner.asTerm, name.valueOrAbort).asExpr |
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,15 @@ | ||
package examples.select | ||
|
||
|
||
import scala.language.dynamics | ||
import examples.select.Wrapper | ||
|
||
object Dynamic0: | ||
|
||
@main | ||
def runTimeError = | ||
|
||
val w = Wrapper(Option(1)) | ||
println(w.isEmpty) | ||
|
||
end Dynamic0 |