From c50e82bdbcf12fa6f66ec60da6b7bb7cb944933b Mon Sep 17 00:00:00 2001 From: Mark Ipatov Date: Fri, 7 Mar 2025 11:24:03 +0100 Subject: [PATCH] Added restrictions to inner and local classes --- docs/src/md/kotlin.core/declarations.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/src/md/kotlin.core/declarations.md b/docs/src/md/kotlin.core/declarations.md index 929378fe..9e7a42d0 100644 --- a/docs/src/md/kotlin.core/declarations.md +++ b/docs/src/md/kotlin.core/declarations.md @@ -246,6 +246,8 @@ Inner classes cannot be declared in a [statement scope][Scopes and identifiers], Inner classes cannot be declared in [object declarations][Object declaration], as object declarations also create a single named value of their type, which makes additional association unnecessary. +Inner classes cannot contain any nested classes, interfaces or objects (including companion objects but excluding object literals). Additional inner classes are allowed inside an inner class. + > Note: for information on how type parameters of parent and nested / inner classifiers interoperate, we delegate you to the [type system][Inner and nested type contexts] section of the specification. > Note: unlike object declarations, in [object literals] only inner classes are allowed, as types of object literals are anonymous, making their nested classifiers available only through explicit receiver, effectively forcing them to be inner. @@ -867,6 +869,8 @@ fun foo() { } ``` +Local classes have restrictions similar to object literals and [inner classes][Nested and inner classifiers]; only inner classes are allowed in local classes. Nested classes, interfaces or objects are forbidden. + Enum classes and annotation classes cannot be declared locally. #### Classifier initialization