davegurnell/bridges

Types with lists are wrong for Elm

Opened this issue · 0 comments

When a type contains a list of values, the generated encoder for Elm is wrong.
The reason is that the type of Encode.list is

Encode.list: (a -> Value) -> List a -> Value

but it is used with an encoder myEncoder: a -> Value in the following construct

Encode.list (List.map myEncoder listOfA)

which is a type error.

Reconstruction

import bridges.core.syntax._
import bridges.elm.Elm

object Issue {

  case class Child(
      number: Int
  )

  case class Parent(
      children: List[Child]
  )

  def main(args: Array[String]): Unit = {
    val (_, content) = Elm.buildFile(
      module = "TestModule",
      decls = List(
        decl[Child],
        decl[Parent]
      ),
      customTypeReplacements = Map.empty
    )
    println(content)
  }

}

The List.map needs to be removed entirely, which fixes the issue.