goggles icon indicating copy to clipboard operation
goggles copied to clipboard

Unclear CTE using `set"..." ~= { ... }` with a generic case class

Open oleg-py opened this issue 8 years ago • 1 comments

I was trying to use goggles to modify a value inside a case class with a type parameter (type parameters should remain the same).

Simplified, code like this:

import goggles._
case class Boxed[+A](get: A)
set"${Boxed(1)}.get" ~= { _ + 1 }

results in following error:

The types of consecutive sections don't match.
 found   : Playground.this.Boxed[Int]
 required: Playground.this.Boxed[Int] 

 Sections │ Types            │ Optics 
──────────┼──────────────────┼────────
 $        │ Boxed[Int]       │        
 .get     │ Boxed[Int]  ⇒  A │ Setter

while I would expect Boxed(2), it would be nice even if compile-time error was less misleading.

oleg-py avatar Nov 01 '17 12:11 oleg-py

Good catch, thanks for the report! It works if the case class doesn't have type parameters, so clearly it's choking on the generics.

scala> case class BoxI(get: Int)
defined class BoxI

scala> set"${BoxI(1)}.get" ~= { _ + 1 }
res5: BoxI = BoxI(2)

kenbot avatar Nov 02 '17 23:11 kenbot