5

I try to use shapless lenses of version 2.0.0 for scala 2.10.3 I have the code similar to this one:

import shapeless._
case class A(map: Map[String, String])
case class B(a: A)
val mapLens = lens[B] >> 'a >> 'map 

the infered type in idea of mapLens is

AnyRef with Lens[B, Nothing] {val gen: LabelledGeneric.Aux[Nothing, ::[record.FieldType[Witness.Lt[Symbol]#T, Nothing], Nothing]]}

so if I want to change value of B instance

mapLens.set(b)(b.a.map + ("foo" -> "bar"))

I get a type mismatch error. How to fix this?

P.S. Here there is an example of using shapeless lenses. How does this lens[Person].address.street works? I mean how does compiler allow us to call methods of case class on instance of lense class? Because in LenseExamples object the >> operator is used

edit Have tried in REPL and it works. Idea says that it

could not find implicit value for evidence parameter of type shapeless.LabelledGeneric[B]{type Repr = Out0}

The same complain emits gradle

maks
  • 5,911
  • 17
  • 79
  • 123
  • Have you tried this outside IDEA (ie. using SBT, or in Eclipse)? – Miles Sabin May 26 '14 at 17:34
  • No, haven't tried yet? Can this be a reason? My IDEA uses compiler of vresion 2.10.3 as well as gradle project where this code resides – maks May 26 '14 at 18:36
  • All I can say is that I tried your example briefly on the REPL and I didn't see `Nothing` inferred anywhere. – Miles Sabin May 27 '14 at 02:18
  • Suppose it works in scala REPL and sbt because they have dependecy on scala compiler(either compile or runtime dependecy). When adding runtime dependency of scala compiler to gradle and running `gradle scalaConsole` task it works. However, when I build or test my project through gradle it emits the same error with implicit evidence absence – maks May 27 '14 at 10:25

1 Answers1

8

Idea is wrong. You should report a bug against the Scala plugin.

Miles Sabin
  • 23,015
  • 6
  • 61
  • 95