diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2012-08-16 01:39:37 +0200 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2012-08-16 01:39:37 +0200 |
commit | 3c4ccbd6588caa88f3e7de6f687c885bd3ee6682 (patch) | |
tree | 66ba1d8aa1603594c679b729384668b3d03d1322 /src/compiler | |
parent | 72518506a353fecd4a4927dfff18630329b1c4aa (diff) | |
download | scala-3c4ccbd6588caa88f3e7de6f687c885bd3ee6682.tar.gz scala-3c4ccbd6588caa88f3e7de6f687c885bd3ee6682.tar.bz2 scala-3c4ccbd6588caa88f3e7de6f687c885bd3ee6682.zip |
more macro cleanup
Diffstat (limited to 'src/compiler')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Macros.scala | 50 |
1 files changed, 11 insertions, 39 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala index f5ab9c6dd5..d87c864491 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala @@ -275,9 +275,7 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { val paramCache = collection.mutable.Map[Symbol, Symbol]() def param(tree: Tree): Symbol = paramCache.getOrElseUpdate(tree.symbol, { - // [Eugene] deskolemization became necessary once I implemented inference of macro def return type - // please, verify this solution, but for now I'll leave it here - cargo cult for the win - val sym = tree.symbol.deSkolemize + val sym = tree.symbol val sigParam = makeParam(sym.name, sym.pos, implType(sym.isType, sym.tpe)) if (sym.isSynthetic) sigParam.flags |= SYNTHETIC sigParam @@ -479,22 +477,14 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { macroTraceVerbose("body of a macro def failed to typecheck: ")(ddef) } else { if (!hasError) { - if (macroImpl == null) { - invalidBodyError() - } else { - if (!macroImpl.isMethod) - invalidBodyError() - if (!macroImpl.isPublic) - reportError(implpos, "macro implementation must be public") - if (macroImpl.isOverloaded) - reportError(implpos, "macro implementation cannot be overloaded") - if (!macroImpl.typeParams.isEmpty && (!rhs1.isInstanceOf[TypeApply])) - reportError(implpos, "macro implementation reference needs type arguments") - if (!hasError) - validatePostTyper(rhs1) + if (macroImpl == null) invalidBodyError() + else { + if (!macroImpl.isMethod) invalidBodyError() + if (!macroImpl.isPublic) reportError(implpos, "macro implementation must be public") + if (macroImpl.isOverloaded) reportError(implpos, "macro implementation cannot be overloaded") + if (!macroImpl.typeParams.isEmpty && !rhs1.isInstanceOf[TypeApply]) reportError(implpos, "macro implementation reference needs type arguments") + if (!hasError) validatePostTyper(rhs1) } - if (hasError) - macroTraceVerbose("macro def failed to satisfy trivial preconditions: ")(macroDef) } if (!hasError) { bindMacroImpl(macroDef, rhs1) // we must bind right over here, because return type inference needs this info @@ -631,29 +621,11 @@ trait Macros extends scala.tools.reflect.FastTrack with Traces { } def computeMacroDefTypeFromMacroImpl(macroDdef: DefDef, macroDef: Symbol, macroImpl: Symbol): Type = { - // get return type from method type - def unwrapRet(tpe: Type): Type = { - def loop(tpe: Type) = tpe match { - case NullaryMethodType(ret) => ret - case mtpe @ MethodType(_, ret) => unwrapRet(ret) - case _ => tpe - } - - tpe match { - case PolyType(_, tpe) => loop(tpe) - case _ => loop(tpe) - } - } - var metaType = unwrapRet(macroImpl.tpe) - // downgrade from metalevel-0 to metalevel-1 - def inferRuntimeType(metaType: Type): Type = metaType match { - case TypeRef(pre, sym, args) if sym.name == tpnme.Expr && args.length == 1 => - args.head - case _ => - AnyClass.tpe + var runtimeType = macroImpl.tpe.finalResultType.dealias match { + case TypeRef(pre, sym, runtimeType :: Nil) if sym == ExprClass => runtimeType + case _ => AnyTpe } - var runtimeType = inferRuntimeType(metaType) // transform type parameters of a macro implementation into type parameters of a macro definition runtimeType = runtimeType map { |