Skip to content

outer class inaccessible during initialization of inner class in Scala 2.13.0 #11736

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

Closed
joschua-fink opened this issue Sep 14, 2019 · 4 comments · Fixed by scala/scala#8431
Closed
Assignees
Labels
Milestone

Comments

@joschua-fink
Copy link

trait Foo {
  trait Bar {
    println(Foo.this)
  }
}

abstract class Foo1 extends Foo

object Foo2 extends Foo1 {
  new Bar {}
}

Foo2

In Scala 2.13.0 the example above unexpectely prints null. Making Foo1 a trait or Foo2 something else than an object solves the issue. The example works as expected in Scala 2.12.10.

@som-snytt
Copy link

som-snytt commented Sep 15, 2019

Probably related to scala/scala#7270 from last fall, in RC1.

I don't do the crossword any more so maybe I'll find time to finally understand the conversations on that ticket.

The trait version that works

+       at Foo$Bar.$init$(t11736.scala:5)
+       at Foo2$$anon$1.<init>(t11736.scala:14)
+       at Foo2$.<clinit>(t11736.scala:14)

versus

        at Foo$Bar.$init$(t11736.scala:5)
        at Foo2$$anon$1.<init>(t11736.scala:12)
        at Foo2$.<init>(t11736.scala:12)
        at Foo2$.<clinit>(t11736.scala:11)

I don't quite have time tonight, it's a school night.

@SethTisue
Copy link
Member

@retronym @lrytz interested in looking into this?

@som-snytt
Copy link

som-snytt commented Sep 17, 2019

There is an elaborate before-and-after or he-said-she-said test at scala/scala#8425 where retronym lrytz will say it blows the complexity budget.

@lrytz
Copy link
Member

lrytz commented Sep 19, 2019

The problem is that the first statement in object Foo2 is a new. The implementation fails to tell this apart from the super call, and puts it in the wrong place. The following works correctly (added a println):

trait Foo {
  trait Bar {
    println(Foo.this)
  }
}

abstract class Foo1 extends Foo

object Foo2 extends Foo1 {
  println("statement after the super call")
  new Bar {}
}

Foo2

Fix in scala/scala#8431.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants