Skip to content

Commit 9821af0

Browse files
Merge pull request #14201 from dotty-staging/fix-#14185
Remove reflect TypeApply TypeVars
2 parents 53ab457 + e491319 commit 9821af0

File tree

3 files changed

+65
-3
lines changed

3 files changed

+65
-3
lines changed

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1882,13 +1882,13 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
18821882

18831883
object AppliedType extends AppliedTypeModule:
18841884
def unapply(x: AppliedType): (TypeRepr, List[TypeRepr]) =
1885-
(x.tycon, x.args)
1885+
(AppliedTypeMethods.tycon(x), AppliedTypeMethods.args(x))
18861886
end AppliedType
18871887

18881888
given AppliedTypeMethods: AppliedTypeMethods with
18891889
extension (self: AppliedType)
1890-
def tycon: TypeRepr = self.tycon
1891-
def args: List[TypeRepr] = self.args
1890+
def tycon: TypeRepr = self.tycon.stripTypeVar
1891+
def args: List[TypeRepr] = self.args.mapConserve(_.stripTypeVar)
18921892
end extension
18931893
end AppliedTypeMethods
18941894

tests/pos-macros/i14185/Macro_1.scala

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import scala.quoted.*
2+
3+
object Test {
4+
inline def foo[A, M[_]]: Unit = ${ fooImpl[A, M] }
5+
6+
private def fooImpl[A, M[_]](
7+
using
8+
q: Quotes,
9+
tc: Type[M],
10+
pt: Type[A]
11+
): Expr[Unit] = {
12+
import q.reflect.*
13+
14+
val ptpe = TypeRepr.of[A]
15+
val neededGivenType = TypeRepr.of[M](using tc).appliedTo(ptpe)
16+
17+
val neededGiven: Option[Term] = Implicits.search(neededGivenType) match {
18+
case suc: ImplicitSearchSuccess =>
19+
Some(suc.tree)
20+
21+
case _ =>
22+
None
23+
}
24+
25+
neededGiven.map(_.show)
26+
27+
'{ () }
28+
}
29+
}
30+
31+
// ---
32+
33+
/** Type level evidence that type `A` is not type `B`. */
34+
final class IsNot[A, B]() {
35+
override val toString = "not"
36+
}
37+
38+
object IsNot {
39+
implicit def defaultEvidence[A, B]: IsNot[A, B] = new IsNot[A, B]()
40+
41+
@annotation.implicitAmbiguous("Could not prove type ${A} is not (IsNot) ${A}")
42+
implicit def ambiguousEvidence1[A]: IsNot[A, A] = null
43+
implicit def ambiguousEvidence2[A]: IsNot[A, A] = null
44+
}
45+
46+
// ---
47+
48+
sealed trait SomeTypeclass[T]
49+
50+
object SomeTypeclass extends SomeTypeclassLowPrio {
51+
52+
given collection[T, Repr <: Iterable[T]](
53+
using SomeTypeclass[T],
54+
Repr IsNot Option[T]
55+
): SomeTypeclass[Repr] = new SomeTypeclass[Repr] {}
56+
}
57+
58+
sealed trait SomeTypeclassLowPrio {
59+
given int: SomeTypeclass[Int] = new SomeTypeclass[Int] {}
60+
}

tests/pos-macros/i14185/Test_2.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def test =
2+
Test.foo[Seq[Int], SomeTypeclass]

0 commit comments

Comments
 (0)