Skip to content

Commit cd89fed

Browse files
mboveldwijnandnoti0na1odersky
committed
Change isStatic to isStaticOwner in hasLocalInstantiation
Co-Authored-By: Dale Wijnand <[email protected]> Co-Authored-By: noti0na1 <[email protected]> Co-Authored-By: odersky <[email protected]>
1 parent 9715eed commit cd89fed

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ object ExplicitOuter {
227227
private def hasLocalInstantiation(cls: ClassSymbol)(using Context): Boolean =
228228
// Modules are normally locally instantiated, except if they are declared in a trait,
229229
// in which case they will be instantiated in the classes that mix in the trait.
230-
cls.owner.ownersIterator.takeWhile(!_.isStatic).exists(_.isTerm)
230+
cls.owner.ownersIterator.takeWhile(!_.isStaticOwner).exists(_.isTerm)
231231
|| cls.is(Private, butNot = Module)
232232
|| cls.is(Module) && !cls.owner.is(Trait)
233233

tests/run/19569.scala

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
object helper {
2+
def assertNoParams(cls: Class[?]) = assert(cls.getConstructors()(0).getParameterCount == 0)
3+
}
4+
import helper.assertNoParams
5+
6+
object T1 { class C1; assertNoParams(classOf[C1]) }
7+
object T2 { new AnyRef { class C2; assertNoParams(classOf[C2]) } }
8+
object T3 { def t3(): Unit = { class C3; assertNoParams(classOf[C3]) } }
9+
object T4 { def t4(): Unit = new AnyRef { class C4; assertNoParams(classOf[C4]) } }
10+
11+
//class T5 { class C5; assertNoParams(classOf[C5]) }
12+
class T6 { new AnyRef { class C6; assertNoParams(classOf[C6]) } }
13+
class T7 { def t7(): Unit = { class C7; assertNoParams(classOf[C7]) } }
14+
class T8 { def t8(): Unit = new AnyRef { class C8; assertNoParams(classOf[C8]) } }
15+
16+
object Test {
17+
def main(args: Array[String]): Unit = {
18+
T1.toString
19+
T2.toString
20+
T3.t3()
21+
T4.t4()
22+
//new T5().toString
23+
new T6().toString
24+
new T7().t7()
25+
new T8().t8()
26+
}
27+
}

0 commit comments

Comments
 (0)