You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Subsection 8.6.1 "Exhaustive when expressions" provides a following code example:
sealedinterfaceI1sealedinterfaceI2sealedinterfaceI3classD1 : I1, I2classD2 : I1, I3sealedclassD3 : I1, I3funfoo() {
val b:I1= mk()
val c =when(a) {
!isI3-> {} // covers D1isD2-> {} // covers D2// D3 is sealed and does not take part// in the exhaustiveness check
}
}
As there is no property a in scope to act as a subject value for the illustrated when-expression, the example is somewhat confusing.
The following correction for the probably-typo in question is suggested:
sealedinterfaceI1sealedinterfaceI2sealedinterfaceI3classD1 : I1, I2classD2 : I1, I3sealedclassD3 : I1, I3funfoo(a:I1) {
val c =when (a) {
!isI3-> {} // covers D1isD2-> {} // covers D2// D3 is sealed and does not take part// in the exhaustiveness check
}
}
However, there's more. If one applies the specification's definition of when exhaustiveness to this example, then, in order for D1 to be considered covered, the following conditions must be satisfied:
I3 <: I1
D1 </: I3
there exists k such that k != 1 and Dk <: I3
There are no problems with either condition 2 or 3 (k == 2); however, condition 1 is seemingly not satisfied. The code itself compiles fine, so it seems to be a bug either in the implementation or in the specification.
The text was updated successfully, but these errors were encountered:
Subsection 8.6.1 "Exhaustive when expressions" provides a following code example:
As there is no property
a
in scope to act as a subject value for the illustrated when-expression, the example is somewhat confusing.The following correction for the probably-typo in question is suggested:
However, there's more. If one applies the specification's definition of when exhaustiveness to this example, then, in order for D1 to be considered covered, the following conditions must be satisfied:
I3 <: I1
D1 </: I3
k
such thatk != 1
andDk <: I3
There are no problems with either condition 2 or 3 (
k == 2
); however, condition 1 is seemingly not satisfied. The code itself compiles fine, so it seems to be a bug either in the implementation or in the specification.The text was updated successfully, but these errors were encountered: