Skip to content

Commit

Permalink
bail on RefinedLT and equalValidateInference
Browse files Browse the repository at this point in the history
  • Loading branch information
erikerlandson committed Apr 20, 2020
1 parent 4b7126c commit f198171
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 102 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
package eu.timepit.refined

import eu.timepit.refined.api.{Inference, RefinedLT, Validate}
import eu.timepit.refined.api.Inference.==>
import eu.timepit.refined.generic._
import eu.timepit.refined.api.Validate
import eu.timepit.refined.internal.WitnessAs
import shapeless._
import shapeless.ops.coproduct.ToHList
import shapeless.ops.hlist.ToList
import shapeless.ops.record.Keys

/** Module for generic predicates. */
object generic extends GenericInference {
object generic {

/** Predicate that checks if a value is equal to `U`. */
final case class Equal[U](u: U)
Expand Down Expand Up @@ -101,11 +99,3 @@ object generic extends GenericInference {
Validate.alwaysPassed(Supertype())
}
}

private[refined] trait GenericInference {
implicit def equalValidateInference[U, P](
implicit
tvp: RefinedLT[U, P]
): Equal[U] ==> P =
Inference(s"equalValidateInference(${tvp.expr})")
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package eu.timepit.refined.macros

import eu.timepit.refined.api.{RefinedLT, RefType, Validate}
import eu.timepit.refined.api.{RefType, Validate}
import eu.timepit.refined.char.{Digit, Letter, LowerCase, UpperCase, Whitespace}
import eu.timepit.refined.collection.NonEmpty
import eu.timepit.refined.internal.{Resources, WitnessAs}
import eu.timepit.refined.internal.Resources
import eu.timepit.refined.numeric.{Negative, NonNegative, NonPositive, Positive}
import scala.reflect.macros.blackbox

Expand Down Expand Up @@ -38,27 +38,6 @@ class RefineMacro(val c: blackbox.Context) extends MacroUtils with LiteralMatche
): c.Expr[FTP] =
c.Expr[FTP](impl(t)(rt, v).tree)

def implRefLT[L: c.WeakTypeTag, T: c.WeakTypeTag, P: c.WeakTypeTag](
w: c.Expr[WitnessAs[L, T]],
v: c.Expr[Validate[T, P]]
): c.Expr[RefinedLT[L, P]] = {
// doing eval(v) before eval(w) is important for... reasons.
val validate = eval(v)
val litval = w.tree match {
case q"$_.WitnessAs.natWitnessAs[..$_]($_, new $_.Inst[..$_]($lv).asInstanceOf[..$_], $_)" => {
// trying to eval the Nat witness directly confuses the typer, it is
// tripping on some type recursion involving _5 and Succ[_4] in same expression
eval(c.Expr[T](lv))
}
case _ => eval(w).snd
}
val res = validate.validate(litval)
if (res.isFailed) {
abort(validate.showResult(litval, res))
}
RefinedLT.manifest[L, T, P](c)(w, v)
}

private def validateInstance[T, P](v: c.Expr[Validate[T, P]])(
implicit
T: c.WeakTypeTag[T],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import shapeless.test.illTyped
class AutoSpec extends Properties("auto") {
property("autoInfer") = secure {
val a: Char Refined Equal[W.`'0'`.T] = '0'
val b: Char Refined Digit = a
val b: Char Refined Digit = '0'
illTyped(
"val c: Char Refined Letter = a",
"""type mismatch.*"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import shapeless.test.illTyped
class CollectionInferenceSpec extends Properties("CollectionInference") {
import shim.Inference

/*
property("Exists[A] ==> Exists[B]") = secure {
Inference[Contains[W.`'5'`.T], Exists[Digit]].isValid
}

*/
property("Exists ==> NonEmpty") = secure {
Inference[Exists[Digit], NonEmpty].isValid
}
Expand Down

This file was deleted.

0 comments on commit f198171

Please sign in to comment.