Skip to content

Commit

Permalink
KEEP #4
Browse files Browse the repository at this point in the history
- Explicitly specify restrictions on abbreviated types with projections as top-level arguments - as for regular types.
- Local and nested type aliases are not supported in 1.1.
  • Loading branch information
dnpetrov committed Nov 21, 2016
1 parent 07e62d5 commit ff2eaaa
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion proposals/type-aliases.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ Variance and constraints for type parameters of the generic type aliases are not
> it will be reported with additional details about type alias expansion context.
Type aliases can be top-level declarations, member declarations, or local declarations.

In **Kotlin 1.1**, only top-level type alias declarations are supported.
See [Nested type aliases](#nested_type_aliases) for more details.
```
toplevelObject
: ...
Expand Down Expand Up @@ -394,6 +397,20 @@ val example1 = N(1) // Ok
val example2 = N("") // Error: upper bound violated
```
If the corresponding expanded type contains type projections as top-level arguments, it can not be constructed, and can not be a supertype
(same restriction applies to classes and interfaces).
```
class CInv<T>
interface IInv<T>

typealias COut<T> = CInv<out T>
interface IOut<T> = IInv<out T>

val example1 = COut<Number>() // Error: expanded type CInv<out Number> can not be constructed

class Example2 : IOut<Number> // Error: expanded type IInv<out Number> can not be a supertype
```
### Type alias constructors for inner classes
> Question: how should we better deal with the type arguments?
Expand Down Expand Up @@ -480,7 +497,36 @@ class C<T>: T1<T>, T2<T> {
> NB type arguments can't be specified in super qualifier for classes and interfaces.
## Nested type aliases
## <a name="nested_type_aliases"></a>Nested type aliases
> Only top-level type aliases are supported in **Kotlin 1.1**.
> Main problem is that currently we have no scope that would capture type parameters of a class,
> but not a receiver value.
> Such scopes roughly correspond to static scope in C#.
>
> Example 1:
> ```
> class Outer<T> {
> typealias Set = HashSet<T>
> }
>
> // This syntax is currently not supported in qualified expression resolution:
> val example1 = Outer<String>.Set()
> ```
>
> Example 2:
> ```
> class Outer1<T1> {
> inner class Inner1
> }
>
> class Outer2<T2> {
> // What is the signature of type alias constructor for A
> // corresponding to 'Outer1<T1>.Inner1()'?
> typealias A = Outer1<T2>.Inner1
> }
> ```
Type aliases declared in classes, objects, or interfaces are called nested.
Same resolution rules are applied for nested type aliases as for other nested classifiers.
Expand Down

0 comments on commit ff2eaaa

Please sign in to comment.