Created
March 2, 2014 17:08
-
-
Save travisbrown/9309747 to your computer and use it in GitHub Desktop.
Breaking parametricity sucks!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.brianmckenna.wartremover | |
package warts | |
object Typecase extends WartTraverser { | |
def apply(u: WartUniverse): u.Traverser = { | |
import u.universe._ | |
val typedFinder = new Traverser { | |
override def traverse(tree: Tree) { | |
tree match { | |
case Typed(_, _) => u.error(tree.pos, "Type matching is disabled!") | |
case _ => super.traverse(tree) | |
} | |
} | |
} | |
new Traverser { | |
override def traverse(tree: Tree) { | |
tree match { | |
case CaseDef(pattern, _, _) => typedFinder.traverse(pattern) | |
case _ => super.traverse(tree) | |
} | |
} | |
} | |
} | |
} |
This is not always a wart -- e.g. when pattern matching on case classes with type parameters, Scala sometimes cannot correctly infer the types and you are instead forced to match by type.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example of usage:
See e.g. this article for some arguments on the other side.