softwaremill/quicklens

Doesn't work with literal type

user753 opened this issue · 3 comments

scala 3.2.2
quicklens v1.9.2

case class Test(f: "foo")
Test("foo").modify(_.f).setTo("foo")
[error]    |  Test("foo").modify(_.f).setTo("foo")
[error]    |  ^^^^^^^^^^^^^^^^^^^^^^^
[error]    |  Found:    String
[error]    |  Required: ("foo" : String)
  Test("foo").modify(_.f).setTo("foo": "foo")

also doesn't work

Now it should be possible to do

case class Test(f: "foo")
Test("foo").modify["foo"](_.f).setTo("foo")

Thanks.
Is it the compiler limitation that the generic type need to be specified?

Test("foo").modify(_.f)

Found:    String
Required: ("foo" : String)

The issue is with type inference. The compiler infers the type parameter of modify to be String. In general, the compiler avoids inferring singleton types ATM. It's not necessarily a limitation, but a design choice.