diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 3de7f0bfc670..d261edf5c3b2 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -1882,13 +1882,13 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler object AppliedType extends AppliedTypeModule: def unapply(x: AppliedType): (TypeRepr, List[TypeRepr]) = - (x.tycon, x.args) + (AppliedTypeMethods.tycon(x), AppliedTypeMethods.args(x)) end AppliedType given AppliedTypeMethods: AppliedTypeMethods with extension (self: AppliedType) - def tycon: TypeRepr = self.tycon - def args: List[TypeRepr] = self.args + def tycon: TypeRepr = self.tycon.stripTypeVar + def args: List[TypeRepr] = self.args.mapConserve(_.stripTypeVar) end extension end AppliedTypeMethods diff --git a/tests/pos-macros/i14185/Macro_1.scala b/tests/pos-macros/i14185/Macro_1.scala new file mode 100644 index 000000000000..c30f65dac67c --- /dev/null +++ b/tests/pos-macros/i14185/Macro_1.scala @@ -0,0 +1,60 @@ +import scala.quoted.* + +object Test { + inline def foo[A, M[_]]: Unit = ${ fooImpl[A, M] } + + private def fooImpl[A, M[_]]( + using + q: Quotes, + tc: Type[M], + pt: Type[A] + ): Expr[Unit] = { + import q.reflect.* + + val ptpe = TypeRepr.of[A] + val neededGivenType = TypeRepr.of[M](using tc).appliedTo(ptpe) + + val neededGiven: Option[Term] = Implicits.search(neededGivenType) match { + case suc: ImplicitSearchSuccess => + Some(suc.tree) + + case _ => + None + } + + neededGiven.map(_.show) + + '{ () } + } +} + +// --- + +/** Type level evidence that type `A` is not type `B`. */ +final class IsNot[A, B]() { + override val toString = "not" +} + +object IsNot { + implicit def defaultEvidence[A, B]: IsNot[A, B] = new IsNot[A, B]() + + @annotation.implicitAmbiguous("Could not prove type ${A} is not (IsNot) ${A}") + implicit def ambiguousEvidence1[A]: IsNot[A, A] = null + implicit def ambiguousEvidence2[A]: IsNot[A, A] = null +} + +// --- + +sealed trait SomeTypeclass[T] + +object SomeTypeclass extends SomeTypeclassLowPrio { + + given collection[T, Repr <: Iterable[T]]( + using SomeTypeclass[T], + Repr IsNot Option[T] + ): SomeTypeclass[Repr] = new SomeTypeclass[Repr] {} +} + +sealed trait SomeTypeclassLowPrio { + given int: SomeTypeclass[Int] = new SomeTypeclass[Int] {} +} diff --git a/tests/pos-macros/i14185/Test_2.scala b/tests/pos-macros/i14185/Test_2.scala new file mode 100644 index 000000000000..0dbe4b5ea3b7 --- /dev/null +++ b/tests/pos-macros/i14185/Test_2.scala @@ -0,0 +1,2 @@ +def test = + Test.foo[Seq[Int], SomeTypeclass]