https://kotlinlang.org logo
m

mattmoore

05/15/2020, 8:51 PM
This is awesome! Really looking forward to this.
f

Fudge

05/16/2020, 1:49 PM
Is it not possible to have a syntax of the form
String | Int
instead of
Union2<String, Int>
?
Copy code
fun f(): Union2<String, Union2<Int, Double>> = 2
           fun y(): Union3<String, Int, Double> = f()
           fun x(): Int? = y()
Shouldn’t
x()
produce a type mismatch compilation error since
y()
may return types that are not
Int?
?
i

Imran/Malic

05/16/2020, 6:06 PM
Shouldn’t 
x()
 produce a type mismatch compilation error since 
y()
 may return types that are not 
Int?
?
If they do it simply results in null. That is one of the proofs defined in the prelude.
In other words there is a proof to unbox a Union to a given type, if it is part of the union.
r

raulraja

05/16/2020, 6:46 PM
It won’t let you unbox to a type that is not in the union, but if the type is in the union you access it safely with its nullable type without matching or folding in all cases
i

Imran/Malic

05/16/2020, 6:50 PM
A bit poorly phrased from my side. 😄 I get why that could be misunderstood.