Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

imap for create Codec doesn't work with opaque types #583

Open
shadowsmind opened this issue Dec 4, 2021 · 1 comment
Open

imap for create Codec doesn't work with opaque types #583

shadowsmind opened this issue Dec 4, 2021 · 1 comment

Comments

@shadowsmind
Copy link

shadowsmind commented Dec 4, 2021

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
@shadowsmind
Copy link
Author

Problem solved: need to define codec in same context with opaque types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant