Skip to content

Commit 6ac6da8

Browse files
authored
Merge pull request scala#6004 from retronym/ticket/10423
Don't assume final member class in another comp. unit will stay final
2 parents 8721ec3 + f4c8aab commit 6ac6da8

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

src/compiler/scala/tools/nsc/transform/Constructors.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,7 @@ abstract class Constructors extends Statics with Transform with TypingTransforme
764764
primaryConstrBody.expr)
765765
})
766766

767-
if (omittableAccessor.exists(_.isOuterField) && !constructorStats.exists(_.exists { case i: Ident if i.symbol.isOuterParam => true; case _ => false}))
767+
if ((exitingPickler(clazz.isAnonymousClass) || clazz.originalOwner.isTerm) && omittableAccessor.exists(_.isOuterField) && !constructorStats.exists(_.exists { case i: Ident if i.symbol.isOuterParam => true; case _ => false}))
768768
primaryConstructor.symbol.updateAttachment(OuterArgCanBeElided)
769769

770770
val constructors = primaryConstructor :: auxConstructors

test/files/run/t10423/A_1.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
class Outer {
2+
final class Inner {
3+
def foo: Unit = ()
4+
}
5+
}
6+
object Test {
7+
def main(args: Array[String]): Unit = {
8+
val o = new Outer
9+
new o.Inner().foo
10+
}
11+
}

test/files/run/t10423/A_2.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
class Outer {
2+
class Inner {
3+
def foo: Unit = assert(Outer.this ne null)
4+
}
5+
}
6+

0 commit comments

Comments
 (0)