chimney icon indicating copy to clipboard operation
chimney copied to clipboard

Transform into singleton types

Open MateuszKubuszok opened this issue 8 months ago • 3 comments

Currently the only kinds support for singleton types we have are:

  • case objects (Scala 2 & 3) and parametherless enum cases (Scala 3)
  • filling Unit as constructor parameter/setter
  • filling None as constructor parameter/setter if we enable it with a flag enableOptionDefaultsToNone

We could allow transformting into/filling automatically any literal singleton types (e.g. Strings, Ints, etc literal types), since there is only 1 possible value that can be filled and we know exactly what's that value is.

Implementation would require:

  • creating new datatype in chimney-macro-commons
  • implementing macros (2.12/2.13/3) which would check that a type is singleton type
  • implementing new rule
  • testing
  • checking that this new rule is not colliding with existing rules (e.g. we explicitly ignore None in some methods, so perhaps we should ignore some singleton types or only support primitives literals: Unit/String/Int/numerical types)

MateuszKubuszok avatar Oct 18 '23 11:10 MateuszKubuszok