From 37a7f4825b6953732a3bbea0b80bb211f17b021f Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 11 Nov 2019 20:55:44 +0100 Subject: [PATCH] Fix #7532: Do not search for ClassTag types are equal --- .../src/dotty/tools/dotc/typer/Typer.scala | 2 +- tests/pos/i7532.scala | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 tests/pos/i7532.scala 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