typelevel / typelevel/skunk

Nonterminating Compilation on wide Codec with mismatch types with Encoder

Open
#334 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Scala
Stars
1.7k
Forks
175
Avg merge
5d 14h
Merged PRs (30d)
9

Description

Skunk version 0.0.20

I have an Codec that is 31 columns wide and if I create an Encoder that doesn't match the types the compiler doesn't terminate.

  import skunk._
  import skunk.implicits._
  import skunk.codec.all._
  import java.time.LocalDateTime

   val transactionCodec =
      text ~ // accountId: String
        text.opt ~ // accountOwner: Option[String]
        text.opt ~ // address: Option[String]
        float8 ~ // amount: Double
        timestamp.opt ~ // authorizedDate: Option[LocalDateTime]
        text.opt ~ // byOrderOf: Option[String]
        text ~ // categoryId: String
        text.opt ~ // city: Option[String]
        text.opt ~ // country: Option[String]
        timestamp ~ // date: LocalDateTime
        text.opt ~ // isoCurrencyCode: Option[String]
        float8.opt ~ // lat: Option[Double]
        float8.opt ~ // lon: Option[Double]
        text.opt ~ // merchantName: Option[String]
        text ~ // name: String
        text ~ // originalDescription: String
        text.opt ~ // payee: Option[String]
        text.opt ~ // payer: Option[String]
        text ~ // paymentChannel: String
        text.opt ~ // paymentMethod: Option[String]
        text.opt ~ // paymentProcessor: Option[String]
        bool ~ // pending: Boolean
        text.opt ~ // pendingTransactionId: Option[String]
        text ~ // postalCode: String,
        text.opt ~ // ppdId: Option[String],
        text.opt ~ // reason: Option[String]
        text.opt ~ // referenceNumber: Option[String]
        text.opt ~ // storeNumber: Option[String]
        text.opt ~ // transactionCode: Option[String]
        text ~ // transactionId: String
        text.opt ~ // unofficialCurrencyCode: Option[String]
        text // userId: String


    case class Transaction2(
    accountId: String,
    accountOwner: Option[String],
    address: Option[String],
    amount: Double,
    authorizedDate: Option[LocalDateTime],
    byOrderOf: Option[String],
    categoryId: String,
    city: Option[String],
    country: Option[String],
    date: LocalDateTime,
    isoCurrencyCode: Option[String],
    lat: Option[Double],
    lon: Option[Double],
    merchantName: Option[String],
    name: String,
    originalDescription: String,
    payee: Option[String],
    payer: Option[String],
    paymentChannel: String,
    paymentMethod: Option[String],
    paymentProcessor: Option[String],
    pending: Boolean,
    pendingTransactionId: Option[String],
    postalCode: String,
    ppdId: Option[String],
    reason: Option[String],
    referenceNumber: Option[String],
    storeNumber: Option[String],
    transactionCode: Option[String],
    transactionId: String,
    unofficialCurrencyCode: Option[String],
    userId: String
)    
    val transactionEncoder =
     transactionCodec.values.contramap((t: Transaction2) =>
        t.accountId ~
          t.accountOwner ~
          t.address ~
          t.amount ~
          t.authorizedDate ~
          t.byOrderOf ~
          t.categoryId ~
          t.city ~
          t.country ~
          t.date ~
          t.isoCurrencyCode ~
          t.lat  ~
          t.lon ~
          t.merchantName ~
          t.name ~
          t.originalDescription ~
          t.payee ~
          t.payer ~
          t.paymentChannel ~
          t.paymentMethod ~
          t.paymentProcessor ~
          t.pending ~
          t.pendingTransactionId ~
          t.postalCode ~
          t.ppdId ~
          t.reason ~
          t.referenceNumber ~
          t.storeNumber ~
          t.transactionCode ~
          t.transactionId ~
          t.unofficialCurrencyCode ~
          t.userId 
      )

This compiles fine in a console but when you change one of the types of the Encoder e.g. float8 -> float4, the compiler fails to terminate.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reported 31-column transactionCodec and transactionEncoder reproduction in this issue, then compare compilation with matching types and with float8 changed to float4. Trace the Scala compiler/type-level expansion involved in the mismatch. Done means the mismatched encoder no longer causes nontermination and instead produces a finite diagnostic or otherwise terminates.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgres, scala
Domain
database
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.