Skip to content

Commit 37a7f48

Browse files
committed
Fix #7532: Do not search for ClassTag types are equal
1 parent 3cb93f3 commit 37a7f48

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ class Typer extends Namer
679679
* @pre We are in pattern-matching mode (Mode.Pattern)
680680
*/
681681
def tryWithClassTag(tree: Typed, pt: Type)(implicit ctx: Context): Tree = tree.tpt.tpe.dealias match {
682-
case tref: TypeRef if !tref.symbol.isClass && !ctx.isAfterTyper =>
682+
case tref: TypeRef if !tref.symbol.isClass && !ctx.isAfterTyper && !(tref =:= pt) =>
683683
require(ctx.mode.is(Mode.Pattern))
684684
inferImplicit(defn.ClassTagClass.typeRef.appliedTo(tref),
685685
EmptyTree, tree.tpt.span)(ctx.retractMode(Mode.Pattern)) match {

tests/pos/i7532.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
class Tasty {
3+
type Term
4+
type Select <: Term
5+
6+
given scala.reflect.ClassTag[Term] = ???
7+
given scala.reflect.ClassTag[Select] = ???
8+
object Select {
9+
def unapply(x: Select): Boolean = ???
10+
}
11+
}
12+
13+
object Foo {
14+
def impl(given tasty: Tasty): Unit = {
15+
import tasty.{_, given}
16+
val Select() = (??? : Term)
17+
}
18+
}

0 commit comments

Comments
 (0)