diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 505da8883248..538b1226093e 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -679,7 +679,7 @@ class Typer extends Namer * @pre We are in pattern-matching mode (Mode.Pattern) */ def tryWithClassTag(tree: Typed, pt: Type)(implicit ctx: Context): Tree = tree.tpt.tpe.dealias match { - case tref: TypeRef if !tref.symbol.isClass && !ctx.isAfterTyper => + case tref: TypeRef if !tref.symbol.isClass && !ctx.isAfterTyper && !(tref =:= pt) => require(ctx.mode.is(Mode.Pattern)) inferImplicit(defn.ClassTagClass.typeRef.appliedTo(tref), EmptyTree, tree.tpt.span)(ctx.retractMode(Mode.Pattern)) match { diff --git a/tests/pos/i7532.scala b/tests/pos/i7532.scala new file mode 100644 index 000000000000..173dc7da8d9d --- /dev/null +++ b/tests/pos/i7532.scala @@ -0,0 +1,18 @@ + +class Tasty { + type Term + type Select <: Term + + given scala.reflect.ClassTag[Term] = ??? + given scala.reflect.ClassTag[Select] = ??? + object Select { + def unapply(x: Select): Boolean = ??? + } +} + +object Foo { + def impl(given tasty: Tasty): Unit = { + import tasty.{_, given} + val Select() = (??? : Term) + } +} \ No newline at end of file