[FE 1.0] Check for type mismatch for empty when statements

^KT-47922 Fixed
This commit is contained in:
Dmitriy Novozhilov
2021-08-04 13:16:04 +03:00
committed by TeamCityServer
parent 60195114c1
commit 8578f0beea
24 changed files with 487 additions and 22 deletions
@@ -0,0 +1,11 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION
sealed class Sealed {
}
fun foo(s: Sealed): Int {
return <!NO_ELSE_IN_WHEN!>when<!>(s) {
// We do not return anything, so else branch must be here
}
}
@@ -1,12 +1,11 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_EXPRESSION
sealed class Sealed {
}
fun foo(s: Sealed): Int {
return <!NO_ELSE_IN_WHEN!>when<!>(s) {
return <!TYPE_MISMATCH!><!NO_ELSE_IN_WHEN!>when<!>(s) {
// We do not return anything, so else branch must be here
}
}<!>
}
+21
View File
@@ -0,0 +1,21 @@
// ISSUE: KT-47922
package whencase.castissue
sealed class SealedBase {
object Complete : SealedBase()
}
abstract class NonSealedBase {
object Complete : NonSealedBase()
}
sealed class ToState
val sealedTest: SealedBase.() -> ToState? = {
<!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!>(this) {}
}
val nonSealedTest: NonSealedBase.() -> ToState? = {
when(this) {}
}
+21
View File
@@ -0,0 +1,21 @@
// ISSUE: KT-47922
package whencase.castissue
sealed class SealedBase {
object Complete : SealedBase()
}
abstract class NonSealedBase {
object Complete : NonSealedBase()
}
sealed class ToState
val sealedTest: SealedBase.() -> ToState? = {
<!TYPE_MISMATCH!><!NON_EXHAUSTIVE_WHEN_STATEMENT!>when<!>(this) {}<!>
}
val nonSealedTest: NonSealedBase.() -> ToState? = {
<!TYPE_MISMATCH!>when(this) {}<!>
}
+44
View File
@@ -0,0 +1,44 @@
package
package whencase {
package whencase.castissue {
public val nonSealedTest: whencase.castissue.NonSealedBase.() -> whencase.castissue.ToState?
public val sealedTest: whencase.castissue.SealedBase.() -> whencase.castissue.ToState?
public abstract class NonSealedBase {
public constructor NonSealedBase()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public object Complete : whencase.castissue.NonSealedBase {
private constructor Complete()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
public sealed class SealedBase {
protected constructor SealedBase()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
public object Complete : whencase.castissue.SealedBase {
private constructor Complete()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
public sealed class ToState {
protected constructor ToState()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
}