From ff2eaaa3c4fafcce6a11d67e54a00a2db4d69aad Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Mon, 21 Nov 2016 17:57:34 +0300 Subject: [PATCH] KEEP #4 - 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. --- proposals/type-aliases.md | 48 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/proposals/type-aliases.md b/proposals/type-aliases.md index 7d86b3b2a..922fc436c 100644 --- a/proposals/type-aliases.md +++ b/proposals/type-aliases.md @@ -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 : ... @@ -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 +interface IInv + +typealias COut = CInv +interface IOut = IInv + +val example1 = COut() // Error: expanded type CInv can not be constructed + +class Example2 : IOut // Error: expanded type IInv can not be a supertype +``` + ### Type alias constructors for inner classes > Question: how should we better deal with the type arguments? @@ -480,7 +497,36 @@ class C: T1, T2 { > NB type arguments can't be specified in super qualifier for classes and interfaces. -## Nested type aliases +## 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 { +> typealias Set = HashSet +> } +> +> // This syntax is currently not supported in qualified expression resolution: +> val example1 = Outer.Set() +> ``` +> +> Example 2: +> ``` +> class Outer1 { +> inner class Inner1 +> } +> +> class Outer2 { +> // What is the signature of type alias constructor for A +> // corresponding to 'Outer1.Inner1()'? +> typealias A = Outer1.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.