optics-dev / optics-dev/Monocle
Lenses can't be created for classes with private constructors for Scala 3
Nobody has claimed this yet.
- Dominant language
- Scala
- Stars
- 1.7k
- Forks
- 207
- Avg merge
- 7h 59m
- Merged PRs (30d)
- 5
Description
Hello,
I've noticed that the code that compiles and works fine in scala 2 doesn't work for scala 3.
Scastie:
Scala 2 -> https://scastie.scala-lang.org/FmuLKaM0TpmNvQ3xHdpUSg
Scala 3 -> https://scastie.scala-lang.org/7FBOxnIPQbemh5TomJrUig
Code:
import monocle.syntax.all._
case class A private (field1: String, field2: String)
object A {
def apply(field1: String, field2: String): A = new A(field1, field2)
val copiedObject = A("1", "2").copy(field1 = "3")
val modifiedObject = A("1", "2").focus(_.field1).replace("3")
println(copiedObject)
println(modifiedObject)
}
val copiedObject = A("1", "2").copy(field1 = "3") //compile error
val modifiedObject = A("1", "2").focus(_.field1).replace("3") //compile error
println(copiedObject)
println(modifiedObject)
Error:
missing argument for parameter field2 of method copy in class A: (field1: String, field2: String): Playground.A
method copy cannot be accessed as a member of (from : Playground.A) from module class Playground$.
Could you please clarify whether it is expected behavior?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the two linked Scastie reproductions and compare the Scala 2 and Scala 3 compiler errors for the private case class A example. Then inspect Monocle's Scala 3 lens syntax or derivation entry point; the issue names no repository files or tests. Done means determining whether the behavior is expected and documenting or correcting the supported behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- scala
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100