Marc Knaup
12/24/2019, 3:26 PMNothing, but not for example class functions? Is that a bug?
This is especially confusing if this (unexpectedly?) resolves to Nothing because there’s not even a warning 😅
error("foo").hasSurrogatePairAt(1)Marc Knaup
12/24/2019, 3:26 PMdiesieben07
12/24/2019, 3:27 PMNothing is a subtype of every other type. You can literally put a value of type Nothing everywhere (because such a value can never exist).Marc Knaup
12/24/2019, 3:28 PMdiesieben07
12/24/2019, 3:29 PMdiesieben07
12/24/2019, 3:30 PMAnastasia Finogenova
12/24/2019, 3:31 PMAnastasia Finogenova
12/24/2019, 3:32 PMdiesieben07
12/24/2019, 3:32 PMAnastasia Finogenova
12/24/2019, 3:36 PMdiesieben07
12/24/2019, 3:38 PMNothing (which is correct, because Nothing is a subtype of every other type so it can be the receiver for every extension function), but not instance functions (which should still technically be okay, since Nothing is still a subtype of every other type and so should inherit literally every instance method on every class).Anastasia Finogenova
12/24/2019, 4:15 PMAnastasia Finogenova
12/24/2019, 4:17 PMAnastasia Finogenova
12/24/2019, 4:18 PMAnastasia Finogenova
12/24/2019, 4:19 PMMarc Knaup
12/24/2019, 4:26 PMNothing, but autocompletion won’t tell you 🙂Marc Knaup
12/24/2019, 4:27 PMthis.
After editing some other part of the code, this changed to Nothing and the extension function call was still totally fine. There wasn’t even a warning due to a Kotlin bug.
So I was curious why Nothing behaves so differently in different situations.
And I have no idea why it would be useful to call any function on Nothing, whether extension or not 🤔Anastasia Finogenova
12/24/2019, 4:34 PMMarc Knaup
12/24/2019, 4:35 PM.toDouble()Anastasia Finogenova
12/24/2019, 4:36 PMAnastasia Finogenova
12/24/2019, 4:36 PMAnastasia Finogenova
12/24/2019, 4:38 PMbezrukov
12/24/2019, 4:38 PMAnastasia Finogenova
12/24/2019, 4:40 PMMarc Knaup
12/24/2019, 4:40 PMNothing but not instance members.
b) The “unreachable code” warning doesn’t always work. It didn’t for me which caused an extension function invocation on Nothing to not raise any flags.
Simple example for b)
fun <T> foo(block: T.() -> Unit) {}
fun main() {
foo<Nothing> {
hasSurrogatePairAt(1) // no warning
}
}Anastasia Finogenova
12/24/2019, 4:45 PMAnastasia Finogenova
12/24/2019, 4:46 PMAnastasia Finogenova
12/24/2019, 4:47 PMAnastasia Finogenova
12/24/2019, 4:49 PMMarc Knaup
12/24/2019, 5:01 PMMarc Knaup
12/24/2019, 5:07 PMenum class MyEnum
@UseExperimental(ExperimentalStdlibApi::class)
fun main() {
println(Nothing::class.starProjectedType.isSubtypeOf(typeOf<Any?>())) // true
println(Nothing::class.starProjectedType.isSubtypeOf(typeOf<Unit>())) // false
println(Nothing::class.starProjectedType.isSubtypeOf(typeOf<MyEnum>())) // false
}Marc Knaup
12/24/2019, 5:10 PMbezrukov
12/24/2019, 5:15 PMbezrukov
12/24/2019, 5:17 PMgildor
12/24/2019, 11:22 PM