Skip to content

Commit 26dcab9

Browse files
committed
wip
1 parent f156786 commit 26dcab9

File tree

10 files changed

+229
-132
lines changed

10 files changed

+229
-132
lines changed

compiler/src/dotty/tools/dotc/tastyreflect/ReflectionCompilerInterface.scala

Lines changed: 178 additions & 93 deletions
Large diffs are not rendered by default.

library/src/scala/quoted/matching/package.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ package object matching {
1313
def searchImplicitExpr[T](given tpe: Type[T], qctx: QuoteContext): Option[Expr[T]] = {
1414
import qctx.tasty.{_, given}
1515
searchImplicit(tpe.unseal.tpe) match {
16-
case IsImplicitSearchSuccess(iss) => Some(iss.tree.seal.asInstanceOf[Expr[T]])
17-
case IsImplicitSearchFailure(isf) => None
16+
case iss: ImplicitSearchSuccess => Some(iss.tree.seal.asInstanceOf[Expr[T]])
17+
case isf: ImplicitSearchFailure => None
1818
}
1919
}
2020

library/src/scala/tasty/reflect/CompilerInterface.scala

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,21 +1413,21 @@ trait CompilerInterface {
14131413
type ImplicitSearchResult <: AnyRef
14141414

14151415
type ImplicitSearchSuccess <: ImplicitSearchResult
1416-
def matchImplicitSearchSuccess(isr: ImplicitSearchResult)(given ctx: Context): Option[ImplicitSearchSuccess]
1416+
def isInstanceOfImplicitSearchSuccess(given ctx: Context): IsInstanceOf[ImplicitSearchSuccess]
14171417
def ImplicitSearchSuccess_tree(self: ImplicitSearchSuccess)(given ctx: Context): Term
14181418

14191419
type ImplicitSearchFailure <: ImplicitSearchResult
1420-
def matchImplicitSearchFailure(isr: ImplicitSearchResult)(given ctx: Context): Option[ImplicitSearchFailure]
1420+
def isInstanceOfImplicitSearchFailure(given ctx: Context): IsInstanceOf[ImplicitSearchFailure]
14211421
def ImplicitSearchFailure_explanation(self: ImplicitSearchFailure)(given ctx: Context): String
14221422

14231423
type DivergingImplicit <: ImplicitSearchFailure
1424-
def matchDivergingImplicit(isr: ImplicitSearchResult)(given ctx: Context): Option[DivergingImplicit]
1424+
def isInstanceOfDivergingImplicit(given ctx: Context): IsInstanceOf[DivergingImplicit]
14251425

14261426
type NoMatchingImplicits <: ImplicitSearchFailure
1427-
def matchNoMatchingImplicits(isr: ImplicitSearchResult)(given ctx: Context): Option[NoMatchingImplicits]
1427+
def isInstanceOfNoMatchingImplicits(given ctx: Context): IsInstanceOf[NoMatchingImplicits]
14281428

14291429
type AmbiguousImplicits <: ImplicitSearchFailure
1430-
def matchAmbiguousImplicits(isr: ImplicitSearchResult)(given ctx: Context): Option[AmbiguousImplicits]
1430+
def isInstanceOfAmbiguousImplicits(given ctx: Context): IsInstanceOf[AmbiguousImplicits]
14311431

14321432
/** Find an implicit of type `T` in the current scope given by `ctx`.
14331433
* Return an `ImplicitSearchResult`.

library/src/scala/tasty/reflect/ImplicitsOps.scala

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,42 @@ trait ImplicitsOps extends Core {
55
def searchImplicit(tpe: Type)(given ctx: Context): ImplicitSearchResult =
66
internal.searchImplicit(tpe)
77

8-
object IsImplicitSearchSuccess {
9-
def unapply(isr: ImplicitSearchResult)(given ctx: Context): Option[ImplicitSearchSuccess] =
10-
internal.matchImplicitSearchSuccess(isr)
11-
}
8+
given (given Context): IsInstanceOf[ImplicitSearchSuccess] = internal.isInstanceOfImplicitSearchSuccess
9+
10+
object IsImplicitSearchSuccess
11+
@deprecated("Use _: ImplicitSearchSuccess", "")
12+
def unapply(isr: ImplicitSearchSuccess)(given ctx: Context): Option[ImplicitSearchSuccess] = Some(isr)
1213

1314
given (self: ImplicitSearchSuccess) {
1415
def tree(given ctx: Context): Term = internal.ImplicitSearchSuccess_tree(self)
1516
}
1617

17-
object IsImplicitSearchFailure {
18-
def unapply(isr: ImplicitSearchResult)(given ctx: Context): Option[ImplicitSearchFailure] =
19-
internal.matchImplicitSearchFailure(isr)
20-
}
18+
given (given Context): IsInstanceOf[ImplicitSearchFailure] = internal.isInstanceOfImplicitSearchFailure
19+
20+
object IsImplicitSearchFailure
21+
@deprecated("Use _: ImplicitSearchFailure", "")
22+
def unapply(isr: ImplicitSearchFailure)(given ctx: Context): Option[ImplicitSearchFailure] = Some(isr)
2123

2224
given (self: ImplicitSearchFailure) {
2325
def explanation(given ctx: Context): String = internal.ImplicitSearchFailure_explanation(self)
2426
}
2527

26-
object IsDivergingImplicit {
27-
def unapply(isr: ImplicitSearchResult)(given ctx: Context): Option[DivergingImplicit] =
28-
internal.matchDivergingImplicit(isr)
29-
}
28+
given (given Context): IsInstanceOf[DivergingImplicit] = internal.isInstanceOfDivergingImplicit
3029

31-
object IsNoMatchingImplicits {
32-
def unapply(isr: ImplicitSearchResult)(given ctx: Context): Option[NoMatchingImplicits] =
33-
internal.matchNoMatchingImplicits(isr)
34-
}
30+
object IsDivergingImplicit
31+
@deprecated("Use _: DivergingImplicit", "")
32+
def unapply(isr: DivergingImplicit)(given ctx: Context): Option[DivergingImplicit] = Some(isr)
3533

36-
object IsAmbiguousImplicits {
37-
def unapply(isr: ImplicitSearchResult)(given ctx: Context): Option[AmbiguousImplicits] =
38-
internal.matchAmbiguousImplicits(isr)
39-
}
34+
given (given Context): IsInstanceOf[NoMatchingImplicits] = internal.isInstanceOfNoMatchingImplicits
35+
36+
object IsNoMatchingImplicits
37+
@deprecated("Use _: NoMatchingImplicits", "")
38+
def unapply(isr: NoMatchingImplicits)(given ctx: Context): Option[NoMatchingImplicits] = Some(isr)
39+
40+
given (given Context): IsInstanceOf[AmbiguousImplicits] = internal.isInstanceOfAmbiguousImplicits
41+
42+
object IsAmbiguousImplicits
43+
@deprecated("Use _: AmbiguousImplicits", "")
44+
def unapply(isr: AmbiguousImplicits)(given ctx: Context): Option[AmbiguousImplicits] = Some(isr)
4045

4146
}

tests/run-macros/i6171/Macro_1.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ object scalatest {
88
import qctx.tasty.{_, given}
99
import util._
1010

11-
def isImplicitMethodType(tp: Type): Boolean =
12-
IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty
11+
def isImplicitMethodType(tp: Type): Boolean = tp match
12+
case tp: MethodType => tp.isImplicit
13+
case _ => false
14+
1315
cond.unseal.underlyingArgument match {
1416
case t @ Apply(Select(lhs, op), rhs :: Nil) =>
1517
let(lhs) { left =>

tests/run-macros/reflect-dsl/assert_1.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ object scalatest {
88
import qctx.tasty.{_, given}
99
import util._
1010

11-
def isImplicitMethodType(tp: Type): Boolean =
12-
IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty
11+
def isImplicitMethodType(tp: Type): Boolean = tp match
12+
case tp: MethodType => tp.isImplicit
13+
case _ => false
1314

1415
cond.unseal.underlyingArgument match {
1516
case t @ Apply(sel @ Select(lhs, op), rhs :: Nil) =>

tests/run-macros/reflect-select-constructor/assert_1.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ object scalatest {
88
import qctx.tasty.{_, given}
99
import util._
1010

11-
def isImplicitMethodType(tp: Type): Boolean =
12-
IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty
11+
def isImplicitMethodType(tp: Type): Boolean = tp match
12+
case tp: MethodType => tp.isImplicit
13+
case _ => false
1314

1415
cond.unseal.underlyingArgument match {
1516
case t @ Apply(Select(lhs, op), rhs :: Nil) =>

tests/run-macros/reflect-select-copy-2/assert_1.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ object scalatest {
88
import qctx.tasty.{_, given}
99
import util._
1010

11-
def isImplicitMethodType(tp: Type): Boolean =
12-
IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty
11+
def isImplicitMethodType(tp: Type): Boolean = tp match
12+
case tp: MethodType => tp.isImplicit
13+
case _ => false
1314

1415
cond.unseal.underlyingArgument match {
1516
case Apply(sel @ Select(lhs, op), rhs :: Nil) =>

tests/run-macros/reflect-select-symbol-constructor/assert_1.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ object scalatest {
88
import qctx.tasty.{_, given}
99
import util._
1010

11-
def isImplicitMethodType(tp: Type): Boolean =
12-
IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty
11+
def isImplicitMethodType(tp: Type): Boolean = tp match
12+
case tp: MethodType => tp.isImplicit
13+
case _ => false
1314

1415
cond.unseal.underlyingArgument match {
1516
case t @ Apply(sel @ Select(lhs, op), rhs :: Nil) =>

tests/run-macros/reflect-select-value-class/assert_1.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ object scalatest {
88
import qctx.tasty.{_, given}
99
import util._
1010

11-
def isImplicitMethodType(tp: Type): Boolean =
12-
IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty
11+
def isImplicitMethodType(tp: Type): Boolean = tp match
12+
case tp: MethodType => tp.isImplicit
13+
case _ => false
1314

1415
cond.unseal.underlyingArgument match {
1516
case t @ Apply(Select(lhs, op), rhs :: Nil) =>

0 commit comments

Comments
 (0)