Skip to content

Commit

Permalink
Do not erase arguments of Array expressions in class literals, add ex…
Browse files Browse the repository at this point in the history
…amples (#5)
  • Loading branch information
udalov committed Aug 12, 2016
1 parent 80e9cd3 commit 5d2464e
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions proposals/bound-callable-references.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<T'>` 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<erase(T)>`, 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<A1, ..., AN>`, 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<erase(A1)>`
- TODO: consider type projections here (`Array<out E>`)
- otherwise `erase(T)` = `C<*, ..., *>`

Examples:
```
fun test() {
"a"::class // KClass<String>
listOf("a")::class // KClass<List<*>> (not "KClass<List<String>>"!)
mapOf("a" to 42)::class // KClass<Map<*, *>>
"a"::class // KClass<String>
listOf("a")::class // KClass<List<*>> (not "KClass<List<String>>"!)
listOf(listOf("a"))::class // KClass<List<*>> (not "KClass<List<List<String>>>"!)
mapOf("a" to 42)::class // KClass<Map<*, *>>
arrayOf("a")::class // KClass<Array<String>>
arrayOf(arrayOf("a"))::class // KClass<Array<Array<String>>>
arrayOf(listOf("a"))::class // KClass<Array<List<*>>>
}
```

Expand Down

0 comments on commit 5d2464e

Please sign in to comment.