@antoin_m
Yes - from my understanding it will work as expected with the type simply as the Vec sealed class. No extra casting is needed.
The compiler will correctly show the “exhaustive check” if you add another data class.
Copy code
operator fun Double.times(vec: Vec) = when (vec) {
is Vec2 -> vec.copy(this * vec.x, this * vec.y)
is Vec3 -> vec.copy(this * vec.x, this * vec.y, this * vec.z)
}