propensive / wisteria

Easy, fast, transparent generic derivation of typeclass instances in Scala
https://soundness.dev/wisteria/
Apache License 2.0
19 stars 1 forks source link

`summonInline`/`summonFrom` does not seem to work on field types #20

Open propensive opened 3 weeks ago

propensive commented 3 weeks ago

A proper test is required, but it seems like inline summoning does not work inside polymorphic lambdas, e.g. in

fields(value): [FieldType] =>
  field =>
    summonFrom:
      case given Show[FieldType] => 2
      case _                     => 4

The default case will always match, even if there are Show instances available for each field type.

I think this is a limitation of Scala, because even after inlining, FieldType is a abstract type parameter, and there's never a typeclass instance in-scope for exactly that type parameter.

We could mitigate this by first resolving an IArray of typeclass instances for each field type, and then accessing it by index (which is available in the polymorphic lambda.