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))) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
staring that in case you find a solution. good luck !