Alina Dolgikh [JB]
Manuel Bogner
05/23/2024, 9:42 AMMatt Robertson
05/23/2024, 2:03 PMStephan Schröder
05/23/2024, 8:22 PMManuel Bogner
05/24/2024, 2:33 PMAhsan Ullah Rasel
05/25/2024, 1:41 PMinterface Rho {
operator fun inc(): Sigma = TODO()
}
interface Sigma : Rho {
fun sigma() = Unit
}
interface Tau {
fun tau() = Unit
}
fun main(input: Rho) {
var unknownObject: Rho = input
// Check if unknownObject inherits from the Tau interface
if (unknownObject is Tau) {
// Use the overloaded inc() operator from interface Rho,
// which smart-casts the type of unknownObject to Sigma.
++unknownObject
// In Kotlin 2.0.0, the compiler knows unknownObject has type
// Sigma, so the sigma() function can be called successfully.
unknownObject.sigma()
// In Kotlin 1.9.20, the compiler thinks unknownObject has type
// Tau, so calling the sigma() function throws an error.
// In Kotlin 2.0.0, the compiler knows unknownObject has type
// Sigma, so calling the tau() function throws an error.
unknownObject.tau()
// Unresolved reference 'tau'
// In Kotlin 1.9.20, the compiler mistakenly thinks that
// unknownObject has type Tau, so the tau() function can be
// called successfully.
}
}
Sunil Kumar
05/28/2024, 11:22 AMAndrey Polyakov [JB]
05/28/2024, 1:08 PMAhsan Ullah Rasel
05/28/2024, 1:41 PMAndrey Polyakov [JB]
05/28/2024, 1:50 PMSunil Kumar
05/29/2024, 4:03 PM