Skip to content

Instantly share code, notes, and snippets.

@propensive

propensive/illtyped2.scala

Last active Aug 29, 2015
Embed
What would you like to do?
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

This comment has been minimized.

Copy link

@vil1 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