-
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.
Add documentation and test for indirect summons
- Loading branch information
Showing
6 changed files
with
83 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
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 @@ | ||
TC[C2] generated in macro using: | ||
TC2[_] generated in macro using: | ||
TC[C1] generated in macro |
50 changes: 50 additions & 0 deletions
50
tests/run-macros/summonIgnoring-nonrecursive/Macro_1.scala
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,50 @@ | ||
//> using options -experimental | ||
import scala.quoted._ | ||
class C1 | ||
trait TC[T] { | ||
def print(): Unit | ||
} | ||
|
||
object TC { | ||
implicit transparent inline def auto[T]: TC[T] = ${autoImpl[T]} | ||
def autoImpl[T: Type](using Quotes): Expr[TC[T]] = | ||
import quotes.reflect._ | ||
if (TypeRepr.of[T].typeSymbol == Symbol.classSymbol("C1")){ | ||
'{ | ||
new TC[T] { | ||
def print() = { | ||
println("TC[C1] generated in macro") | ||
} | ||
} | ||
} | ||
} else { | ||
Expr.summonIgnoring[TC2[C1]](Symbol.classSymbol("TC").companionModule.methodMember("auto")*) match | ||
case Some(a) => | ||
'{ | ||
new TC[T] { | ||
def print(): Unit = | ||
println(s"TC[${${Expr(TypeRepr.of[T].show)}}] generated in macro using:") | ||
$a.print() | ||
} | ||
} | ||
case None => | ||
'{ | ||
new TC[T]{ | ||
def print(): Unit = | ||
println(s"TC[${${Expr(TypeRepr.of[T].show)}}] generated in macro without TC2[_]") | ||
} | ||
} | ||
} | ||
} | ||
|
||
trait TC2[T] { | ||
def print(): Unit | ||
} | ||
|
||
object TC2 { | ||
implicit def auto2[T](using tc: TC[T]): TC2[T] = new TC2[T] { | ||
def print(): Unit = | ||
println(s"TC2[_] generated in macro using:") | ||
tc.print() | ||
} | ||
} |
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 @@ | ||
//> using options -experimental | ||
|
||
@main def Test(): Unit = { | ||
class C2 | ||
summon[TC[C2]].print() | ||
} |
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