-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Before 5ae7861 we used to find those types withing the `tpt`. Fixes #17434 #### Other CI tests | Project | Version | Build URL | Notes | | ------- | ------- | --------- | ----- | | dwickern/scala-nameof | 4.0.0 | [Open CB logs](https://github.com/VirtusLab/community-build3/actions/runs/5025314096) | passed | | scalikejdbc/scalikejdbc | 4.0.0 | [Open CB logs](https://github.com/VirtusLab/community-build3/actions/runs/5025351221) | passed | | scalikejdbc/scalikejdbc-async | 0.18.0 | [Open CB logs](https://github.com/VirtusLab/community-build3/actions/runs/5025363289) | passed | | bitlap/scalikejdbc-helper | 0.2.3 -> 0.2.6 | [Open CB logs](https://github.com/VirtusLab/community-build3/actions/runs/5025363289) ([old failure](https://github.com/VirtusLab/community-build3/actions/runs/4897105783/jobs/8746001478) | failed with other issue |
- Loading branch information
Showing
9 changed files
with
77 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
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.* | ||
|
||
object SelectDynamicMacroImpl { | ||
def selectImpl[E: Type]( | ||
ref: Expr[SQLSyntaxProvider[_]], | ||
name: Expr[String] | ||
)(using Quotes): Expr[SQLSyntax] = '{SQLSyntax("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,23 @@ | ||
// test.scala | ||
import scala.language.dynamics | ||
|
||
trait SQLSyntaxProvider[A] extends Dynamic{ | ||
def field(name: String): SQLSyntax = ??? | ||
|
||
inline def selectDynamic(inline name: String): SQLSyntax = | ||
select[A](this, name) | ||
|
||
inline def select[E](ref: SQLSyntaxProvider[A], inline name: String): SQLSyntax = | ||
${ SelectDynamicMacroImpl.selectImpl[E]('ref, 'name) } | ||
} | ||
|
||
class SQLSyntax(value: String) | ||
trait SQLSyntaxSupport[A] | ||
case class ColumnSQLSyntaxProvider[S <: SQLSyntaxSupport[A], A](support: S) extends SQLSyntaxProvider[A] | ||
|
||
case class Account(id: Long, name: String) | ||
object Account extends SQLSyntaxSupport[Account] | ||
|
||
def Test() = | ||
val p = ColumnSQLSyntaxProvider[Account.type, Account](Account) | ||
assert(p.name == SQLSyntax("name")) |
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,29 @@ | ||
trait NameOf: | ||
transparent inline def nameOf(inline expr: Any): String = ${NameOfImpl.nameOf('expr)} | ||
transparent inline def nameOf[T](inline expr: T => Any): String = ${NameOfImpl.nameOf('expr)} | ||
object NameOf extends NameOf | ||
|
||
import scala.compiletime.* | ||
|
||
import scala.annotation.tailrec | ||
import scala.quoted.* | ||
|
||
object NameOfImpl { | ||
def nameOf(expr: Expr[Any])(using Quotes): Expr[String] = { | ||
import quotes.reflect.* | ||
@tailrec def extract(tree: Tree): String = tree match { | ||
case Ident(name) => name | ||
case Select(_, name) => name | ||
case Block(List(stmt), term) => extract(stmt) | ||
case DefDef("$anonfun", _, _, Some(term)) => extract(term) | ||
case Block(_, term) => extract(term) | ||
case Apply(term, _) if term.symbol.fullName != "<special-ops>.throw" => extract(term) | ||
case TypeApply(term, _) => extract(term) | ||
case Inlined(_, _, term) => extract(term) | ||
case Typed(term, _) => extract(term) | ||
case _ => throw new MatchError(s"Unsupported expression: ${expr.show}") | ||
} | ||
val name = extract(expr.asTerm) | ||
Expr(name) | ||
} | ||
} |
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,6 @@ | ||
import NameOf._ | ||
def test() = | ||
def func1(x: Int): String = ??? | ||
val funcVal = func1 _ | ||
assert(nameOf(funcVal) == "funcVal") | ||
assert(nameOf(func1 _) == "func1") |
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,3 @@ | ||
import scala.quoted.* | ||
inline def foo[T](expr: T => Any): Unit = ${impl('expr)} | ||
def impl(expr: Expr[Any])(using Quotes): Expr[Unit] = '{} |
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 @@ | ||
def test(f: Int => Any) = foo(f) |
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 scala.quoted.* | ||
def impl[E: Type](ref: Expr[Foo[_]])(using Quotes): Expr[Unit] = '{ } |
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,4 @@ | ||
trait Foo[A]: | ||
inline def foo(): Unit = bar[this.type](this) | ||
inline def bar[E](ref: Foo[A]): Unit = ${ impl[E]('ref) } | ||
def test(p: Foo[Int]) = p.foo() |