Skip to content

Filter when expression with sealed nullable type where null is the last case #1683

@Godin

Description

@Godin

For the following src/Example.kt

sealed interface S {
  data object S1 : S
  data object S2 : S
  data object S3 : S
}

fun nullFirst(s: S?): String = when (s) {
  null -> "null"
  is S.S1 -> "case 1"
  is S.S2 -> "case 2"
  is S.S3 -> "case 3"
}

fun nullLast(s: S?): String = when (s) {
  is S.S1 -> "case 1"
  is S.S2 -> "case 2"
  is S.S3 -> "case 3"
  null -> "null"
}

fun main() {
  nullFirst(null)
  nullFirst(S.S1)
  nullFirst(S.S2)
  nullFirst(S.S3)

  nullLast(null)
  nullLast(S.S1)
  nullLast(S.S2)
  nullLast(S.S3)
}

execution of

kotlin-2.0.0/bin/kotlinc src -d classes
java -javaagent:jacoco-0.8.12/lib/jacocoagent.jar -cp classes:kotlin-2.0.0/lib/kotlin-stdlib.jar ExampleKt
java -jar jacoco-0.8.12/lib/jacococli.jar report jacoco.exec --classfiles classes --sourcefiles src --html report

produces

Screenshot 2024-08-13 at 12 04 48 Screenshot 2024-08-13 at 12 06 25

Metadata

Metadata

Assignees

Type

No type

Projects

Status

In Progress

Relationships

None yet

Development

No branches or pull requests

Issue actions