typelevel / typelevel/skunk

imap for create Codec doesn't work with opaque types

Open
#583 1 comment 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

setup:

  • 17.0.1
  • sbt 1.5.5
  • scala 3.1.0
  • skunk-core 0.2.2

example:

import skunk._
import skunk.implicits._
import skunk.codec.all._

opaque type AchievId = Long
opaque type AchievTitle = String
opaque type AchievDesc = String
opaque type AchievIconUrl = String
opaque type AchievPoints = Int
opaque type AchievSecret = Boolean

case class AchievementEntity(
  id: AchievId,
  title: AchievTitle,
  description: AchievDesc,
  iconUrl: AchievIconUrl,
  points: AchievPoints,
  isSecret: AchievSecret,
)

val codec: Codec[AchievementEntity] =
    (int8 ~ varchar ~ text ~ varchar ~ int4 ~ bool)
      .imap { case id ~ title ~ desc ~ iconUrl ~ points ~ isSecret =>
        AchievementEntity(
          AchievId(id),
          AchievTitle(title),
          AchievDesc(desc),
          AchievIconUrl(iconUrl),
          AchievPoints(points),
          AchievSecret(isSecret),
        )
      }(e => e.id ~ e.title ~ e.description ~ e.iconUrl ~ e.points ~ e.isSecret)

Compile error:

[error] -- [E007] Type Mismatch Error: D:\Dev\Projects\Achievements\achievements_server\src\main\scala\io\achievements\persistence\achievement\package.scala:22:13
[error] 22 |      }(e => e.id ~ e.title ~ e.description ~ e.iconUrl ~ e.points ~ e.isSecret)
[error]    |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]    |          Found:    (((((io.achievements.domain.achievement.AchievId,
[error]    |            io.achievements.domain.achievement.AchievTitle
[error]    |          ), io.achievements.domain.achievement.AchievDesc),
[error]    |            io.achievements.domain.achievement.AchievIconUrl
[error]    |          ), io.achievements.domain.achievement.AchievPoints),
[error]    |            io.achievements.domain.achievement.AchievSecret
[error]    |          )
[error]    |          Required: (((((Long, String), String), String), Int), Boolean)
[error] one error found
[error] one error found
[error] (Compile / compileIncremental) Compilation failed

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

Reproduce the opaque-type codec example in the reported package.scala location using Scala 3.1.0, sbt 1.5.5, and skunk-core 0.2.2. Start at Codec.imap and run Compile / compileIncremental; done means the shown Codec[AchievementEntity] compiles without the tuple type mismatch.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgres, scala
Domain
backend, 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.