Skip to content

Instantly share code, notes, and snippets.

takezoe / NotVar.scala
Created April 28, 2012 15:09 — forked from xuwei-k/NotVar.scala
not var macro scala
def NotVar(expr: Any): Any = macro NotVarImpl
def NotVarImpl(c: Context)(expr: c.Expr[Any]): c.Expr[Any] = {
import c.mirror._
import reflect.api.Modifier.mutable
Expr((new Transformer{
override def transform(tree:Tree):Tree = tree match{
case ValDef(m,_,_,_) if m.hasModifier(mutable) => sys.error("can't use var !!!")
case _ => super.transform(tree)