Skip to content

Instantly share code, notes, and snippets.

@propensive
Last active August 29, 2015 14:24
Show Gist options
  • Save propensive/f9b467809b0f45956d06 to your computer and use it in GitHub Desktop.
Save propensive/f9b467809b0f45956d06 to your computer and use it in GitHub Desktop.
Alternative implementation of ill-type checker
// Example usages:
// Returns true
checkTypeMismatch {
import deferTypeErrors._
7: String
}
// Returns false
checkTypeMismatch {
import deferTypeErrors._
7: Int
}
// Implementation
object deferTypeErrors {
implicit def deferTypeErrorsConvertAnyToAny[T, S](t: T): S = ???
implicit def deferTypeErrorsResolveAnyImplicit[T]: T = ???
}
object checkTypeMismatch {
def apply[T](fn: => T): Boolean = macro applyMacro[T]
def applyMacro[T](c: BlackboxContext)(fn: c.Expr[T]): c.Expr[Boolean] = {
import c.universe._
val found = fn.tree.exists {
case Select(_, name) => name.decodedName.toString match {
case "deferTypeErrorsConvertAnyToAny" => true
case "deferTypeErrorsResolveAnyImplicit" => true
case _ => false
}
case _ => false
}
c.Expr[Boolean](Literal(Constant(found)))
}
}
@vil1
Copy link

vil1 commented Jul 8, 2015

staring that in case you find a solution. good luck !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment