Skip to content

Fix #1664: Refine isOuterRef condition #1697

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
Nov 16, 2016
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
20 changes: 12 additions & 8 deletions src/dotty/tools/dotc/transform/ExplicitOuter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,18 @@ object ExplicitOuter {
case ref: TermRef =>
if (ref.prefix ne NoPrefix)
!ref.symbol.isStatic && isOuterRef(ref.prefix)
else if (ref.symbol is Hoistable)
// ref.symbol will be placed in enclosing class scope by LambdaLift, so it might need
// an outer path then.
isOuterSym(ref.symbol.owner.enclosingClass)
else
// ref.symbol will get a proxy in immediately enclosing class. If this properly
// contains the current class, it needs an outer path.
ctx.owner.enclosingClass.owner.enclosingClass.isContainedIn(ref.symbol.owner)
else (
(ref.symbol is Hoistable) &&
// ref.symbol will be placed in enclosing class scope by LambdaLift, so it might need
// an outer path then.
isOuterSym(ref.symbol.owner.enclosingClass)
||
// If not hoistable, ref.symbol will get a proxy in immediately enclosing class. If this properly
// contains the current class, it needs an outer path.
// If the symbol is hoistable, it might have free variables for which the same
// reasoning applies. See pos/i1664.scala
ctx.owner.enclosingClass.owner.enclosingClass.isContainedIn(ref.symbol.owner)
)
case _ => false
}
def hasOuterPrefix(tp: Type) = tp match {
Expand Down
12 changes: 12 additions & 0 deletions tests/pos/i1664.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
object test {
def f[a](x: a) = {
def print = x
class A {
def f() = {
class B { def h = print }
new B
}
f()
}
}
}