fun calc(x: List?, y: Int?): Int { x?.subList(y!! - 1, y) // y!! above should not provide smart cast here return y }