File tree Expand file tree Collapse file tree 6 files changed +83
-0
lines changed
summonIgnoring-nonrecursive Expand file tree Collapse file tree 6 files changed +83
-0
lines changed Original file line number Diff line number Diff line change @@ -280,6 +280,17 @@ object Expr {
280280 }
281281 }
282282
283+ /** Find a given instance of type `T` in the current scope,
284+ * while excluding certain symbols from the initial implicit search.
285+ * Return `Some` containing the expression of the implicit or
286+ * `None` if implicit resolution failed.
287+ *
288+ * @tparam T type of the implicit parameter
289+ * @param ignored Symbols ignored during the initial implicit search
290+ *
291+ * @note if the found given requires additional search for other given instances,
292+ * this additional search will NOT exclude the symbols from the `ignored` list.
293+ */
283294 @ scala.annotation.experimental def summonIgnoring [T ](using Type [T ])(using quotes : Quotes )(ignored : quotes.reflect.Symbol * ): Option [Expr [T ]] = {
284295 import quotes .reflect ._
285296 Implicits .searchIgnoring(TypeRepr .of[T ])(ignored* ) match {
Original file line number Diff line number Diff line change @@ -3706,6 +3706,16 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching =>
37063706 */
37073707 def search (tpe : TypeRepr ): ImplicitSearchResult
37083708
3709+ /** Find a given instance of type `T` in the current scope provided by the current enclosing splice,
3710+ * while excluding certain symbols from the initial implicit search.
3711+ * Return an `ImplicitSearchResult`.
3712+ *
3713+ * @param tpe type of the implicit parameter
3714+ * @param ignored Symbols ignored during the initial implicit search
3715+ *
3716+ * @note if an found given requires additional search for other given instances,
3717+ * this additional search will NOT exclude the symbols from the `ignored` list.
3718+ */
37093719 @ experimental def searchIgnoring (tpe : TypeRepr )(ignored : Symbol * ): ImplicitSearchResult
37103720 }
37113721
Original file line number Diff line number Diff line change 1+ TC[C2] generated in macro using:
2+ TC2[_] generated in macro using:
3+ TC[C1] generated in macro
Original file line number Diff line number Diff line change 1+ //> using options -experimental
2+ import scala .quoted ._
3+ class C1
4+ trait TC [T ] {
5+ def print (): Unit
6+ }
7+
8+ object TC {
9+ implicit transparent inline def auto [T ]: TC [T ] = $ {autoImpl[T ]}
10+ def autoImpl [T : Type ](using Quotes ): Expr [TC [T ]] =
11+ import quotes .reflect ._
12+ if (TypeRepr .of[T ].typeSymbol == Symbol .classSymbol(" C1" )){
13+ ' {
14+ new TC [T ] {
15+ def print () = {
16+ println(" TC[C1] generated in macro" )
17+ }
18+ }
19+ }
20+ } else {
21+ Expr .summonIgnoring[TC2 [C1 ]](Symbol .classSymbol(" TC" ).companionModule.methodMember(" auto" )* ) match
22+ case Some (a) =>
23+ ' {
24+ new TC [T ] {
25+ def print (): Unit =
26+ println(s " TC[ ${$ {Expr (TypeRepr .of[T ].show)}}] generated in macro using: " )
27+ $a.print()
28+ }
29+ }
30+ case None =>
31+ ' {
32+ new TC [T ]{
33+ def print (): Unit =
34+ println(s " TC[ ${$ {Expr (TypeRepr .of[T ].show)}}] generated in macro without TC2[_] " )
35+ }
36+ }
37+ }
38+ }
39+
40+ trait TC2 [T ] {
41+ def print (): Unit
42+ }
43+
44+ object TC2 {
45+ implicit def auto2 [T ](using tc : TC [T ]): TC2 [T ] = new TC2 [T ] {
46+ def print (): Unit =
47+ println(s " TC2[_] generated in macro using: " )
48+ tc.print()
49+ }
50+ }
Original file line number Diff line number Diff line change 1+ //> using options -experimental
2+
3+ @ main def Test (): Unit = {
4+ class C2
5+ summon[TC [C2 ]].print()
6+ }
Original file line number Diff line number Diff line change @@ -66,6 +66,9 @@ val experimentalDefinitionInLibrary = Set(
6666 // Added for 3.6.0, stabilize after feedback.
6767 " scala.quoted.Quotes.reflectModule.SymbolModule.newBoundedType" ,
6868 " scala.quoted.Quotes.reflectModule.SymbolModule.newTypeAlias" ,
69+ // Added for 3.7.0, stabilise after feedback
70+ " scala.quoted.Quotes.reflectModule.ImplicitsModule.searchIgnoring" ,
71+ " scala.quoted.Expr.summonIgnoring" ,
6972
7073 // New feature: functions with erased parameters.
7174 // Need erasedDefinitions enabled.
You can’t perform that action at this time.
0 commit comments