https://kotlinlang.org logo
#compiler
Title
# compiler
t

thanh

10/02/2019, 6:44 AM
Can we write a custom syntax for Kotlin with a compiler plugin? Like union type:
type newType = typeA | typeB
?
🚫 2
r

raulraja

10/02/2019, 12:14 PM
You can hack your way into it but it’s easier to modify just typechecking for a valid shape for example:
Copy code
typealias NewType = Union<TypeA, TypeB>
val a: NewType = a // or b

val f : TypeA? = a //ok
val g : TypeB? = a //ok
val h : TypeA? = b //ok
val i : TypeB? = b //ok
val z : TypeB? = other // not ok
👍 2
15 Views