softwaremill / softwaremill/quicklens

Cannot use modify in opaque types

Open
#234 2 comments 0 reactions 1 assignee View on GitHub

@KacperFKorban is already working on this.

Since Jun 30, 2024.

Dominant language
Scala
Stars
852
Forks
53
PR merge metrics
No merged PRs in 30d

Description

Following opaque type has defined both getters and copy, but it is not possible to use quicklens on it:

import com.softwaremill.quicklens.*

object Types {
  case class V(x: Double, y: Double)

  opaque type Vec = V

  object Vec {
    def apply(x: Double, y: Double): Vec = V(x, y)
  }
  extension (v: Vec) {
    def x: Double = v.x
    def y: Double = v.y
    def copy(x: Double = v.x, y: Double = v.y): Vec = V(x, y)
  }
}

object Main {
  import Types.*
  def main(args: Array[String]): Unit = {
    val a = Vec(1, 2)
    val b = a.modify(_.x).using(_ + 1)
    println(b)
  }

}

With Scala 3.4.2 the error is:

Unsupported path element. Path must have shape: .field1.field2.each.field3.(...), got: (($1: Types.Vec) => Types.x($1))
val b = a.modify(
.x).using(_ + 1)

Contributor guide

No contributing guide indexed for this repository

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.