mbonnin
02/21/2024, 11:08 AMinline fun <reified T : Any> Any?.cast(): T = this as T
in the stdlib?
It's been in addToStdLib.kt for a while but looks like it's now deprecated? Is there a fundamental reason this is not possible?dmitriy.novozhilov
02/21/2024, 11:12 AMUsage of this function is unsafe because it does not have native compiler support
This means that compiler won't report UNCHECKED_CAST, CAST_NEVER_SUCCEED or similar diagnostics in case of error cast (which can happen immediately or after some refactoring of class hierarchy)
Consider using regular `as` and `as?`
mbonnin
02/21/2024, 11:22 AMmbonnin
02/21/2024, 11:23 AMdmitriy.novozhilov
02/21/2024, 11:23 AM"hello".as<Int>()
mbonnin
02/21/2024, 11:23 AMdmitriy.novozhilov
02/21/2024, 11:24 AMAnd follow up question is could compiler support be added?It could, but it's not on the table right now
mbonnin
02/21/2024, 11:24 AMmbonnin
02/21/2024, 11:24 AMandylamax
02/21/2024, 11:25 AM