Skip to content

Commit

Permalink
Change isStatic to isStaticOwner in hasLocalInstantiation
Browse files Browse the repository at this point in the history
Co-Authored-By: Dale Wijnand <[email protected]>
Co-Authored-By: noti0na1 <[email protected]>
Co-Authored-By: odersky <[email protected]>
  • Loading branch information
4 people committed Feb 27, 2024
1 parent 9715eed commit cd89fed
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ object ExplicitOuter {
private def hasLocalInstantiation(cls: ClassSymbol)(using Context): Boolean =
// Modules are normally locally instantiated, except if they are declared in a trait,
// in which case they will be instantiated in the classes that mix in the trait.
cls.owner.ownersIterator.takeWhile(!_.isStatic).exists(_.isTerm)
cls.owner.ownersIterator.takeWhile(!_.isStaticOwner).exists(_.isTerm)
|| cls.is(Private, butNot = Module)
|| cls.is(Module) && !cls.owner.is(Trait)

Expand Down
27 changes: 27 additions & 0 deletions tests/run/19569.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
object helper {
def assertNoParams(cls: Class[?]) = assert(cls.getConstructors()(0).getParameterCount == 0)
}
import helper.assertNoParams

object T1 { class C1; assertNoParams(classOf[C1]) }
object T2 { new AnyRef { class C2; assertNoParams(classOf[C2]) } }
object T3 { def t3(): Unit = { class C3; assertNoParams(classOf[C3]) } }
object T4 { def t4(): Unit = new AnyRef { class C4; assertNoParams(classOf[C4]) } }

//class T5 { class C5; assertNoParams(classOf[C5]) }
class T6 { new AnyRef { class C6; assertNoParams(classOf[C6]) } }
class T7 { def t7(): Unit = { class C7; assertNoParams(classOf[C7]) } }
class T8 { def t8(): Unit = new AnyRef { class C8; assertNoParams(classOf[C8]) } }

object Test {
def main(args: Array[String]): Unit = {
T1.toString
T2.toString
T3.t3()
T4.t4()
//new T5().toString
new T6().toString
new T7().t7()
new T8().t8()
}
}

0 comments on commit cd89fed

Please sign in to comment.