Skip to content

Commit

Permalink
Avoid auto-deriving when implicit exists
Browse files Browse the repository at this point in the history
  • Loading branch information
kyri-petrou committed Sep 24, 2023
1 parent e0e0bdd commit ea590ff
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion main/src/io/github/iltotore/iron/RuntimeConstraint.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.github.iltotore.iron

import scala.util.NotGiven

final class RuntimeConstraint[A, T](_test: A => Boolean, val message: String):
inline def test(value: A): Boolean = _test(value)

Expand All @@ -10,5 +12,10 @@ object RuntimeConstraint:

final class AutoDerived[A, T](val inner: RuntimeConstraint[A, T])
object AutoDerived:
inline given derived[A, C](using inline c: Constraint[A, C]): AutoDerived[A, A :| C] =
inline given [A, C](using rtc: RuntimeConstraint[A, A :| C]): AutoDerived[A, A :| C] =
new AutoDerived[A, A :| C](rtc)

inline given [A, C](using inline c: Constraint[A, C], ng: NotGiven[RuntimeConstraint[A, A :| C]]): AutoDerived[A, A :| C] =
new AutoDerived[A, A :| C](RuntimeConstraint.derived[A, C])

end RuntimeConstraint

0 comments on commit ea590ff

Please sign in to comment.