CanEqual instances for enums
For Scala 3.x it would be great if you could enable the"-language:strictEquality" compiler flag without having to define a lot of orphan instances. Was there any consideration in generating these instances?
@LukaJCB we've not really considered it. Truth be told, teams in our organisation are still mostly on Scala 2, so there's a little bit of an ignorance bias there, but I think we'd agree to a PR adding it. We already have some Scala 3 related logic to render wildcards correctly, and also some opt-in to render errors as Scala 3 unions instead of sealed traits.
In the meantime, the pain-point can be alleviated by cheating a little bit, to avoid having to create an instance manually for each and every generated datatype.
// all types generated by smithy4s have an implicit schema
given [A: smithy4s.schema.Schema]: CanEqual[A, A] = CanEqual.derived
It's worth noting that smithy4s offers a mechanism, to provide non-orphan typeclass instances, with the caveat that these instances are meant to be derived from the schema.
But I think CanEqual can be considered a special case, and we could offer a blanket option to render it in the companion object of all generated datatypes. If you're interested in PR'ing it, here are some pointers :
- smithy4s "blanket options" are driven by smithy-metadata. Here's an example of what it looks like.
- The options are retrieved from smithy models here
The renderer would have to be amended to add a line in the generated companion objects of :
- product/structures (case classes)
- unions (sealed traits)
- enumerations
- newtypes
Q: why put it in the companion object instead of derives? For non-newtypes, that is.
Fewer changes to codegen?
Fewer changes to codegen?
yup