Skip to content
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

Nested (non-capturing) type aliases #405

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Open

Nested (non-capturing) type aliases #405

wants to merge 11 commits into from

Conversation

serras
Copy link
Contributor

@serras serras commented Dec 20, 2024

Only comment here about the text itself. The discussion about the feature is done in #406.

Right now type aliases can only be used at the top level. The goal of this document is to propose a design to allow them within other classifiers, in case they do not capture any type parameters of the enclosing declaration.


```kotlin
class Dijkstra {
typelias VisitedNodes = Set<Node>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
typelias VisitedNodes = Set<Node>
typealias VisitedNodes = Set<Node>

typo

// = capture(Inner<Int>, capture(Example<S>, { T }))
// = capture(Inner<Int>, { S })
// = capture(Int) + { S } = { S } ⊆ { S } => OK
typelias Boo<S> = Example<S>.Inner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
typelias Boo<S> = Example<S>.Inner
typealias Boo<S> = Example<S>.Inner

same here

Comment on lines +155 to +158
// capture(Inner<Int>, { T })
// = capture(Int) + { T }
// = { T } ⊈ { T } => not allowed
typealias Moo = Inner<Int>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// capture(Inner<Int>, { T })
// = capture(Int) + { T }
// = { T } ⊈ { T } => not allowed
typealias Moo = Inner<Int>
// capture(Inner<Int>, { T })
// = capture(Int, { T }) + { T }
// = { T } ⊈ { } => not allowed
typealias Moo = Inner<Int>

capture has two "parameters", Moo has no type parameters

> [!TIP]
> As a rule of thumb, a nested type alias is correct if it could be used as the supertype or a parameter type within a nested class living within the same classifier.

We formally define the set of captured type parameters of a type `T` with enclosing parameters `P`, `captured(T, P)`, as follows.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
We formally define the set of captured type parameters of a type `T` with enclosing parameters `P`, `captured(T, P)`, as follows.
We formally define the set of captured type parameters of a type `T` with enclosing parameters `P`, `capture(T, P)`, as follows.

typo

Comment on lines +160 to +164
// capture(Example<S>.Inner<Int>, { T })
// = capture(Inner<Int>, capture(Example<S>, { T }))
// = capture(Inner<Int>, { S })
// = capture(Int) + { S } = { S } ⊆ { S } => OK
typelias Boo<S> = Example<S>.Inner
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// capture(Example<S>.Inner<Int>, { T })
// = capture(Inner<Int>, capture(Example<S>, { T }))
// = capture(Inner<Int>, { S })
// = capture(Int) + { S } = { S } ⊆ { S } => OK
typelias Boo<S> = Example<S>.Inner
// capture(Example<S>.Inner<Int>, { T })
// = capture(Inner<Int>, capture(Example<S>, { T }))
// = capture(Inner<Int>, { S })
// = capture(Int, { S }) + { S } = { S } ⊆ { S } => OK
typelias Boo<S> = Example<S>.Inner<Int>

capture has two "parameters", Inner has a type parameter

Comment on lines +192 to +196
// correctUsage.kt
import A.* // imports `I`
import C.* // imports `D`

val d = A().D()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it seems like this is missing the usage of I:

val i = A().I()

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

Successfully merging this pull request may close these issues.

2 participants