Skip to content

Smart cast and exhaustive when check failures #436

@JarnaChao09

Description

@JarnaChao09

Hi everyone, been working with datalore for a bit and came across something interesting that I was wondering if others would have an explanation for:
I have code that compiles fine locally with gradle and on play.kotlinlang.org, however, this same code does not compile in the latest kotlin kernel for datalore
the main errors I encountered were smart cast and exhaustive when check errors

  • could not smart cast a variable i checked with !! previously to the non-null version of the type
  • could not determine the when statement over a sealed interface type was exhaustive and recommended an else branch
    is the kotlin kernel (for jupyter? or is datalore different?) just behind on these analysis checks? or is there a reason for these analysis checks being dropped?

here is a gist of the code in the datalore notebook: https://gist.github.com/JarnaChao09/24ec66e1f4e13d96a2452977dc193851

thanks for your insight in advance!

Activity

ileasile

ileasile commented on Oct 17, 2023

@ileasile
Collaborator

Hi! Provided code samples seem to work for us. Do they fail for you or you have attached already fixed code samples? It would be also great to have minimal reproducers for both of the problems.

JarnaChao09

JarnaChao09 commented on Oct 19, 2023

@JarnaChao09
Author

Hi, sorry for the late response. I have attached the already fixed code. Lines 158 and 247 were added to satisfy the errors I stated before. This code was tested both in Datalore and the Kotlin Notebooks plugin and resulted in the same errors. Hope that clears things up.

enolive

enolive commented on Jan 16, 2024

@enolive

I discovered this issue when researching why exhaustive when statements don't work properly in the kotlin jupyter kernel. This seems to be the same problem I encountered.
Small reproduction sample (copied into a code cell in Jupyter):

sealed interface MyType
object A : MyType
object B : MyType

fun func(e: MyType) {
    when (e) {
      is A -> TODO()
      is B -> TODO()  
    }
}

Compiler message:

Line_0.jupyter.kts (6:5 - 9) 'when' expression must be exhaustive, add necessary 'else' branch

Screenshot from jupyter notebook

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @ileasile@enolive@JarnaChao09

        Issue actions

          Smart cast and exhaustive when check failures · Issue #436 · Kotlin/kotlin-jupyter