still hoping for an answer: is this compile error ...
# announcements
p
still hoping for an answer: is this compile error expected, and if so, what’s the rationale?
Copy code
class Outer {
  sealed class Foo {}
  
  // cannot access '<init>': it is private in 'Foo'
  class Bar : Foo() {}
}
o
@stanislav.erokhin
n
Maybe it is as rules changed in 1.1?
Copy code
A sealed class can have subclasses, but all of them must be declared in the same file as the sealed class itself. (Before Kotlin 1.1, the rules were even more strict: classes had to be nested inside the declaration of the sealed class).
p
what do you mean by “it is as rules changed”?
it is expected?
n
I mean before 1.1 you could declare it as inner class. After — only as few classes in one file (and not as inner classes).
p
1.1 lifted some restrictions, it didn’t add any
but apparently the enhancements in 1.1 don’t extend to the nested class case. I wonder if they should.
n
Isn’t this a restriction?
Copy code
all of them _must_ be declared in the same file as the sealed class itself
p
no
(not compared to 1.0)
s
It is expected behaviour for now. In 1.0 subclasses for sealed classes was allowed only inside corresponding class, and in 1.1 we allow top-level subclasses for top-level sealed classes. We can support such cases later.