Skip to content

Commit c8f66e4

Browse files
committed
Fix #7783: Widen AnyVal to Any when checking class relation
Widen AnyVal to Any when checking in TypeTestsCasts whether two classes are related.
1 parent e45f03e commit c8f66e4

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

compiler/src/dotty/tools/dotc/transform/TypeTestsCasts.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,8 @@ object TypeTestsCasts {
168168
cpy.TypeApply(tree)(expr1.select(sym).withSpan(expr.span), List(TypeTree(tp)))
169169

170170
def effectiveClass(tp: Type): Symbol =
171-
if (tp.isRef(defn.PairClass)) effectiveClass(erasure(tp))
171+
if tp.isRef(defn.PairClass) then effectiveClass(erasure(tp))
172+
else if tp.isRef(defn.AnyValClass) then defn.AnyClass
172173
else tp.classSymbol
173174

174175
def foundCls = effectiveClass(expr.tpe.widen)

tests/run/i7783.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
object Test extends App {
2+
def foo(t: AnyVal): Unit = t match {
3+
case _: Int =>
4+
}
5+
foo(3)
6+
}

0 commit comments

Comments
 (0)