Skip to content

Commit 1d5a2c4

Browse files
Merge pull request #12617 from dotty-staging/fix-12616
Fix hole in scan for outer references
2 parents 435fc82 + 8f7fd96 commit 1d5a2c4

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

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

+7
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ object ExplicitOuter {
282282
case TypeRef(prefix, _) => isOuterRef(prefix)
283283
case _ => false
284284
}
285+
def containsOuterRefs(tp: Type): Boolean = tp match
286+
case tp: SingletonType => isOuterRef(tp)
287+
case tp: AndOrType => containsOuterRefs(tp.tp1) || containsOuterRefs(tp.tp2)
288+
case _ => false
285289
tree match {
286290
case _: This | _: Ident => isOuterRef(tree.tpe)
287291
case nw: New =>
@@ -292,6 +296,9 @@ object ExplicitOuter {
292296
// newCls might get proxies for free variables. If current class is
293297
// properly contained in newCls, it needs an outer path to newCls access the
294298
// proxies and forward them to the new instance.
299+
case app: TypeApply if app.symbol.isTypeTest =>
300+
// Type tests of singletons translate to `eq` tests with references, which might require outer pointers
301+
containsOuterRefs(app.args.head.tpe)
295302
case _ =>
296303
false
297304
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ object TypeTestsCasts {
295295
derivedTree(expr, defn.Any_asInstanceOf, testType)
296296
}
297297

298-
/** Transform isInstanceOf OrType
298+
/** Transform isInstanceOf
299299
*
300300
* expr.isInstanceOf[A | B] ~~> expr.isInstanceOf[A] | expr.isInstanceOf[B]
301301
* expr.isInstanceOf[A & B] ~~> expr.isInstanceOf[A] & expr.isInstanceOf[B]

tests/pos/i12616.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class Foo:
2+
3+
//object Bar
4+
val Bar = 22
5+
6+
object Baz:
7+
def f(x: Any): Unit =
8+
x match
9+
case s: (Bar.type & x.type) =>

0 commit comments

Comments
 (0)