Skip to content

Fix hole in scan for outer references #12617

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,10 @@ object ExplicitOuter {
case TypeRef(prefix, _) => isOuterRef(prefix)
case _ => false
}
def containsOuterRefs(tp: Type): Boolean = tp match
case tp: SingletonType => isOuterRef(tp)
case tp: AndOrType => containsOuterRefs(tp.tp1) || containsOuterRefs(tp.tp2)
case _ => false
tree match {
case _: This | _: Ident => isOuterRef(tree.tpe)
case nw: New =>
Expand All @@ -292,6 +296,9 @@ object ExplicitOuter {
// newCls might get proxies for free variables. If current class is
// properly contained in newCls, it needs an outer path to newCls access the
// proxies and forward them to the new instance.
case app: TypeApply if app.symbol.isTypeTest =>
// Type tests of singletons translate to `eq` tests with references, which might require outer pointers
containsOuterRefs(app.args.head.tpe)
case _ =>
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ object TypeTestsCasts {
derivedTree(expr, defn.Any_asInstanceOf, testType)
}

/** Transform isInstanceOf OrType
/** Transform isInstanceOf
*
* expr.isInstanceOf[A | B] ~~> expr.isInstanceOf[A] | expr.isInstanceOf[B]
* expr.isInstanceOf[A & B] ~~> expr.isInstanceOf[A] & expr.isInstanceOf[B]
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/i12616.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class Foo:

//object Bar
val Bar = 22

object Baz:
def f(x: Any): Unit =
x match
case s: (Bar.type & x.type) =>