From c8f66e4fdfbefd84f7c28cbf7c8817f923e38c0c Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 16 Dec 2019 21:52:21 +0100 Subject: [PATCH] Fix #7783: Widen AnyVal to Any when checking class relation Widen AnyVal to Any when checking in TypeTestsCasts whether two classes are related. --- .../src/dotty/tools/dotc/transform/TypeTestsCasts.scala | 3 ++- tests/run/i7783.scala | 6 ++++++ 2 files changed, 8 insertions(+), 1 deletion(-) create mode 100644 tests/run/i7783.scala diff --git a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala index 4b31f5ae28cf..a77f892d9c46 100644 --- a/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala +++ b/compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala @@ -168,7 +168,8 @@ object TypeTestsCasts { cpy.TypeApply(tree)(expr1.select(sym).withSpan(expr.span), List(TypeTree(tp))) def effectiveClass(tp: Type): Symbol = - if (tp.isRef(defn.PairClass)) effectiveClass(erasure(tp)) + if tp.isRef(defn.PairClass) then effectiveClass(erasure(tp)) + else if tp.isRef(defn.AnyValClass) then defn.AnyClass else tp.classSymbol def foundCls = effectiveClass(expr.tpe.widen) diff --git a/tests/run/i7783.scala b/tests/run/i7783.scala new file mode 100644 index 000000000000..04a4a2a69f8c --- /dev/null +++ b/tests/run/i7783.scala @@ -0,0 +1,6 @@ +object Test extends App { + def foo(t: AnyVal): Unit = t match { + case _: Int => + } + foo(3) +} \ No newline at end of file