Skip to content

Possible resolution of KT-68726 (Update spec: Nested class prohibited in function scope whilst inner class is allowed) #135

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

Merged
merged 1 commit into from
Mar 7, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/src/md/kotlin.core/declarations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down