From ea590ff5b5776e914c1d157d3f387abbc2b56acc Mon Sep 17 00:00:00 2001 From: Kyri Petrou Date: Sun, 24 Sep 2023 20:08:32 +1000 Subject: [PATCH] Avoid auto-deriving when implicit exists --- main/src/io/github/iltotore/iron/RuntimeConstraint.scala | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/main/src/io/github/iltotore/iron/RuntimeConstraint.scala b/main/src/io/github/iltotore/iron/RuntimeConstraint.scala index 35f6f087..1c5cde8a 100644 --- a/main/src/io/github/iltotore/iron/RuntimeConstraint.scala +++ b/main/src/io/github/iltotore/iron/RuntimeConstraint.scala @@ -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) @@ -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