47degrees / helios

A purely functional JSON library for Kotlin built on Λrrow
https://47degrees.github.io/helios/
Apache License 2.0
169 stars 22 forks source link

Typealias breaks generated code #102

Open Octogonapus opened 5 years ago

Octogonapus commented 5 years ago

A data class which contains a member which is a typealias causes the generated code to be invalid.

This code:

typealias Foo = Either<String, Int>

@json
data class DataClass1(
    val foo: Foo
) {
    companion object
}

Generates this:

fun DataClass1.toJson(): Json = JsObject(mapOf(
"foo" to com.octogonapus.heliosdemo.Foo.encoder().run { foo.encode() }
))

foo.encode() is an unresolved reference.

Changing the data class to:

@json
data class DataClass1(
    val foo: Either<String, Int>
) {
    companion object
}

Generates this, which compiles fine:

fun DataClass1.toJson(): Json = JsObject(mapOf(
"foo" to arrow.core.Either.Companion.encoder(kotlin.String.encoder(), kotlin.Int.encoder()).run { foo.encode() }
))

There is a sample project containing this code here https://github.com/Octogonapus/helios-demo/tree/typealias_issue (specifically on branch typealias_issue).