Iltotore / iron

Strong type constraints for Scala
https://iltotore.github.io/iron/docs/
Apache License 2.0
430 stars 38 forks source link

Allow constraints for non-primitive types to be evaluable at compile-time #147

Open Iltotore opened 1 year ago

Iltotore commented 1 year ago

This is not possible at the moment because Constraint#apply's parameter is not inline. Making it inline would force all children to propagate make it inline too, breaking backward compatibility.

For example, this:

val x: List[String] :| FixedLength[3] = List("a", "b", "c")

is not verifiable at compile-time but this will be easily doable once value in Constraint#apply is inline.

KaranAhlawat commented 8 months ago

If I understand correctly, right now the snippet you shared does not evaluate at compile-time. So, if we were to use it as an IronType, we would necessarily have to write List(...).refine or some equivalent method, yes?

Iltotore commented 8 months ago

Yes. It is currently not possible to use the compile-time conversion with such type.

The fix is simple but would introduce a pretty big compatibility break. Therefore, it will only appear when 3.0.0 will be released.