package eu.timepit.refined
package internal

import shapeless.tag.@@

import scala.reflect.macros.blackbox

object Infer {
  def macroImpl[T: c.WeakTypeTag, A: c.WeakTypeTag, B: c.WeakTypeTag](c: blackbox.Context)(t: c.Expr[T @@ A])(i: c.Expr[InferenceRule[A, B]]): c.Expr[T @@ B] = {
    import c.universe._

    val tTpe = weakTypeOf[T]
    val aTpe = weakTypeOf[A]
    val bTpe = weakTypeOf[B]

    if (MacroUtils.eval(c)(i).isValid)
      c.Expr(q"$t.asInstanceOf[$tTpe @@ $bTpe]")
    else
      c.abort(c.enclosingPosition, s"invalid inference: $aTpe ==> $bTpe")
  }
}

package eu.timepit.refined
package internal

import eu.timepit.refined.InferenceRuleAlias.==>
import shapeless.tag.@@

import scala.reflect.macros.blackbox

object Infer {
  def macroImpl[T: c.WeakTypeTag, A: c.WeakTypeTag, B: c.WeakTypeTag](c: blackbox.Context)(t: c.Expr[T @@ A])(i: c.Expr[A ==> B]): c.Expr[T @@ B] = {
    import c.universe._

    if (MacroUtils.eval(c)(i).isValid)
      c.Expr(q"$t.asInstanceOf[${weakTypeOf[T @@ B]}]")
    else {
      val aTpe = weakTypeOf[A]
      val bTpe = weakTypeOf[B]
      c.abort(c.enclosingPosition, s"invalid inference: $aTpe ==> $bTpe")
    }
  }
}

Fix bug in infer macro
Fix bug in infer macro
