From 5d2464ef1bf025e4f3d0cdaa34228bf093b3bf31 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 12 Aug 2016 16:40:47 +0300 Subject: [PATCH] Do not erase arguments of Array expressions in class literals, add examples (#5) --- proposals/bound-callable-references.md | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/proposals/bound-callable-references.md b/proposals/bound-callable-references.md index 9391e4ce8..7e2a14897 100644 --- a/proposals/bound-callable-references.md +++ b/proposals/bound-callable-references.md @@ -162,12 +162,25 @@ fun test() { } ``` -Once the LHS is type-checked and its type is determined to be `T`, the type of the whole class literal expression is `kotlin.reflect.KClass` where `T'` is a type obtained by _substituting `T`'s arguments with star projections (`*`)_. Example: +Once the LHS is type-checked and its type is determined to be `T`, the type of the whole class literal expression is `KClass`, where `erase(T)` represents the most accurate possible type-safe representation of the type `T` and is obtained by substituting `T`'s arguments with star projections (`*`), except when the type is an array. + +More formally, let `T` = `C`, where `C` is a class and `N`, the number of type arguments, might be zero. `erase(T)` is then defined as follows: +- if `C` = `kotlin.Array`: + - if `A1` = `*`, `erase(T)` = `kotlin.Array<*>` + - otherwise `erase(T)` = `kotlin.Array` + - TODO: consider type projections here (`Array`) +- otherwise `erase(T)` = `C<*, ..., *>` + +Examples: ``` fun test() { - "a"::class // KClass - listOf("a")::class // KClass> (not "KClass>"!) - mapOf("a" to 42)::class // KClass> + "a"::class // KClass + listOf("a")::class // KClass> (not "KClass>"!) + listOf(listOf("a"))::class // KClass> (not "KClass>>"!) + mapOf("a" to 42)::class // KClass> + arrayOf("a")::class // KClass> + arrayOf(arrayOf("a"))::class // KClass>> + arrayOf(listOf("a"))::class // KClass>> } ```