-
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.
Browse files
Browse the repository at this point in the history
Backports #19915 to the LTS branch. PR submitted by the release tooling. [skip ci]
- Loading branch information
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 |