From 7de38fd6a8155c5938e3169b51559a857b8ab90a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Koz=C5=82owski?= Date: Sat, 6 Mar 2021 00:44:53 +0100 Subject: [PATCH] Add inference for #917 --- .../main/scala-3.0-/eu/timepit/refined/boolean.scala | 6 ++++++ .../eu/timepit/refined/BooleanInferenceSpec.scala | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/modules/core/shared/src/main/scala-3.0-/eu/timepit/refined/boolean.scala b/modules/core/shared/src/main/scala-3.0-/eu/timepit/refined/boolean.scala index 755ff1da5..7ceea9139 100644 --- a/modules/core/shared/src/main/scala-3.0-/eu/timepit/refined/boolean.scala +++ b/modules/core/shared/src/main/scala-3.0-/eu/timepit/refined/boolean.scala @@ -273,6 +273,12 @@ private[refined] trait BooleanInference0 extends BooleanInference1 { implicit def conjunctionCommutativity[A, B]: (A And B) ==> (B And A) = Inference.alwaysValid("conjunctionCommutativity") + implicit def dontknownhowtocallthis[A, B, C]: (A And B) ==> (A And (B Or C)) = + Inference.alwaysValid("aaaaaaaaaa") + + implicit def dontknownhowtocallthis2[A, B, C]: ((A And B) Or (A And C)) ==> A = + Inference.alwaysValid("aaaaaaaaaa") + implicit def conjunctionEliminationR[A, B, C](implicit p1: B ==> C): (A And B) ==> C = p1.adapt("conjunctionEliminationR(%s)") diff --git a/modules/core/shared/src/test/scala-3.0-/eu/timepit/refined/BooleanInferenceSpec.scala b/modules/core/shared/src/test/scala-3.0-/eu/timepit/refined/BooleanInferenceSpec.scala index 802ac75a4..72de664eb 100644 --- a/modules/core/shared/src/test/scala-3.0-/eu/timepit/refined/BooleanInferenceSpec.scala +++ b/modules/core/shared/src/test/scala-3.0-/eu/timepit/refined/BooleanInferenceSpec.scala @@ -5,6 +5,8 @@ import eu.timepit.refined.api.Inference import eu.timepit.refined.boolean._ import eu.timepit.refined.char.{Digit, Letter, UpperCase, Whitespace} import eu.timepit.refined.numeric._ +import eu.timepit.refined.string._ +import eu.timepit.refined.collection._ import org.scalacheck.Prop._ import org.scalacheck.Properties import shapeless.test.illTyped @@ -20,6 +22,14 @@ class BooleanInferenceSpec extends Properties("BooleanInference") { Inference[Not[Not[UpperCase]], UpperCase].isValid } + property("example 1") = secure { + Inference[NonEmpty And ValidLong, NonEmpty And (ValidLong Or ValidDouble)].isValid + } + + property("example 2") = secure { + Inference[(NonEmpty And ValidLong) Or (NonEmpty And ValidDouble), NonEmpty].isValid + } + property("double negation elimination 2x") = secure { Inference[Not[Not[Not[Not[UpperCase]]]], UpperCase].isValid }