Skip to content

Commit 0c95f6e

Browse files
Merge pull request #6268 from dotty-staging/fix-static-inner
Don't emit inner classes as static classes
2 parents 45a4cb7 + ba6f2da commit 0c95f6e

File tree

6 files changed

+16
-14
lines changed

6 files changed

+16
-14
lines changed

compiler/src/dotty/tools/backend/jvm/BackendInterface.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -583,8 +583,8 @@ abstract class BackendInterface extends BackendInterfaceDefinitions {
583583
* object T { def f { object U } }
584584
* the owner of U is T, so UModuleClass.isStatic is true. Phase travel does not help here.
585585
*/
586-
def isOriginallyStaticOwner: Boolean
587-
586+
def isOriginallyStaticOwner: Boolean =
587+
isPackageClass || isModuleClass && originalOwner.isOriginallyStaticOwner
588588

589589
def samMethod(): Symbol
590590

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -839,18 +839,6 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
839839
toDenot(sym).owner.is(Flags.PackageClass)
840840
}
841841

842-
/**
843-
* This is basically a re-implementation of sym.isStaticOwner, but using the originalOwner chain.
844-
*
845-
* The problem is that we are interested in a source-level property. Various phases changed the
846-
* symbol's properties in the meantime, mostly lambdalift modified (destructively) the owner.
847-
* Therefore, `sym.isStatic` is not what we want. For example, in
848-
* object T { def f { object U } }
849-
* the owner of U is T, so UModuleClass.isStatic is true. Phase travel does not help here.
850-
*/
851-
def isOriginallyStaticOwner: Boolean = sym.isStatic
852-
853-
854842
def addRemoteRemoteExceptionAnnotation: Unit = ()
855843

856844
def samMethod(): Symbol =

compiler/test/dotc/run-test-pickling.blacklist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ instances.scala
1515
instances-anonymous.scala
1616
mixin-forwarder-overload
1717
t8905
18+
t10889

tests/run/t10889.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
new O(o).I[](i)

tests/run/t10889/O.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package p
2+
class O(val o: String) {
3+
class I[T](val i: String) {
4+
println(s"new O($o).I[]($i)")
5+
}
6+
}

tests/run/t10889/Test.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
public class Test {
2+
public static void main(String[] args) {
3+
p.O l = new p.O("o");
4+
p.O.I<Object> s = l.new I<Object>(/*l,*/ "i");
5+
}
6+
}

0 commit comments

Comments
 (0)