Details

      Description

      I realize I'm pushing the envelope here, but it would be really useful, plus it just bugs me when the compiler's left hand doesn't know what the right hand is transforming.

      import scala.language.experimental.macros
      import scala.reflect.macros.Context
      
      final class Ops[T](val x: T) extends AnyVal {
        def f = macro Macros.crash
      }
      
      object Macros {
        def crash(c: Context): c.Expr[Unit] = c.universe.reify(())
      }
      
      uncaught exception during compilation: scala.reflect.internal.Types$TypeError
      error: scala.reflect.internal.Types$TypeError: macro implementation not found: extension$f (the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them)
        at scala.tools.nsc.typechecker.Contexts$Context.error(Contexts.scala:403)
      

        Activity

        Hide
        Eugene Burmako added a comment -

        Here's a different error if one compiles a macro and its usage separately:

        C:\Projects\Kepler\sandbox @ topic/paramss>myke run .
        error:
             while compiling: Test_2.scala
                during phase: extmethods
             library version: version 2.10.0-20121007-121305-65ed97ed55
            compiler version: version 2.10.0-20121007-121305-65ed97ed55
          reconstructed args: -language:experimental.macros
        
          last tree to typer: This(class Ops)
                      symbol: class Ops (flags: final)
           symbol definition: final class Ops[T] extends AnyVal
                         tpe: Ops[T]
               symbol owners: class Ops -> package <empty>
              context owners: macro method f -> class Ops -> package <empty>
        
        == Enclosing template or block ==
        
        Apply( // final def extension$f[T]($this: Ops[T]): Unit in object Ops
          TypeApply( // final def extension$f[T]($this: Ops[T]): Unit in object Ops, tree.tpe=($this: Ops[T])Unit
            "Ops"."extension$f" // final def extension$f[T]($this: Ops[T]): Unit in object Ops, tree.tpe=[T]($this: Ops[T])Unit
            <tpt> // tree.tpe=T
          )
          This("Ops")final class Ops[T] extends AnyVal, tree.tpe=Ops[T]
        )
        
        == Expanded type of tree ==
        
        TypeRef(
          TypeSymbol(final class Ops[T] extends AnyVal)
          args = List(TypeParamTypeRef(TypeParam(T)))
        )
        
        uncaught exception during compilation: scala.reflect.internal.Types$TypeError
        error: scala.reflect.internal.Types$TypeError: exception during macro expansion:
        java.lang.IllegalArgumentException: wrong number of arguments
        
                at scala.tools.nsc.typechecker.Contexts$Context.error(Contexts.scala:403)
                at scala.tools.nsc.typechecker.ContextErrors$TyperContextErrors$TyperErrorGen$.macroExpansionError(ContextErrors.scala:680)
                at scala.tools.nsc.typechecker.ContextErrors$TyperContextErrors$TyperErrorGen$.MacroGeneratedException(ContextErrors.scala:739)
                at scala.tools.nsc.typechecker.Macros$class.liftedTree1$1(Macros.scala:791)
                at scala.tools.nsc.typechecker.Macros$class.scala$tools$nsc$typechecker$Macros$$macroExpandWithRuntime(Macros.scala:768)
                at scala.tools.nsc.typechecker.Macros$$anonfun$scala$tools$nsc$typechecker$Macros$$macroExpand1$1.apply(Macros.scala:741)
                at scala.tools.nsc.typechecker.Macros$$anonfun$scala$tools$nsc$typechecker$Macros$$macroExpand1$1.apply(Macros.scala:732)
                at scala.tools.nsc.Global.withInfoLevel(Global.scala:189)
                at scala.tools.nsc.typechecker.Macros$class.scala$tools$nsc$typechecker$Macros$$macroExpand1(Macros.scala:732)
                at scala.tools.nsc.typechecker.Macros$class.macroExpand(Macros.scala:697)
                at scala.tools.nsc.Global$$anon$1.macroExpand(Global.scala:490)
                at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:1115)
                at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5448)
                at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5490)
                at scala.tools.nsc.typechecker.Typers$Typer.typedPos(Typers.scala:5494)
                at scala.tools.nsc.transform.ExtensionMethods$Extender$$anonfun$9.apply(ExtensionMethods.scala:175)
                at scala.tools.nsc.transform.ExtensionMethods$Extender$$anonfun$9.apply(ExtensionMethods.scala:175)
                at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:1938)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:34)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:28)
                at scala.tools.nsc.transform.ExtensionMethods$Extender.transform(ExtensionMethods.scala:174)
                at scala.tools.nsc.transform.ExtensionMethods$Extender.transform(ExtensionMethods.scala:102)
                at scala.reflect.api.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:1931)
                at scala.reflect.api.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:1929)
                at scala.collection.immutable.List.loop$1(List.scala:164)
                at scala.collection.immutable.List.mapConserve(List.scala:180)
                at scala.reflect.api.Trees$Transformer.transformStats(Trees.scala:1929)
                at scala.tools.nsc.transform.ExtensionMethods$Extender.transformStats(ExtensionMethods.scala:188)
                at scala.tools.nsc.transform.ExtensionMethods$Extender.transformStats(ExtensionMethods.scala:102)
                at scala.reflect.internal.Trees$class.itransform(Trees.scala:1234)
                at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:12)
                at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:12)
                at scala.reflect.api.Trees$Transformer.transform(Trees.scala:1910)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.scala$tools$nsc$transform$TypingTransformers$TypingTransformer$$super$transform(TypingTransformers.scala:44)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$1.apply(TypingTransformers.scala:44)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$1.apply(TypingTransformers.scala:44)
                at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:1938)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:34)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:28)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:44)
                at scala.tools.nsc.transform.ExtensionMethods$Extender.transform(ExtensionMethods.scala:144)
                at scala.tools.nsc.transform.ExtensionMethods$Extender.transform(ExtensionMethods.scala:102)
                at scala.reflect.api.Trees$Transformer.transformTemplate(Trees.scala:1915)
                at scala.reflect.internal.Trees$$anonfun$itransform$4.apply(Trees.scala:1238)
                at scala.reflect.internal.Trees$$anonfun$itransform$4.apply(Trees.scala:1237)
                at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:1938)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:34)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:28)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:19)
                at scala.reflect.internal.Trees$class.itransform(Trees.scala:1236)
                at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:12)
                at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:12)
                at scala.reflect.api.Trees$Transformer.transform(Trees.scala:1910)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:48)
                at scala.tools.nsc.transform.ExtensionMethods$Extender.transform(ExtensionMethods.scala:183)
                at scala.tools.nsc.transform.ExtensionMethods$Extender.transform(ExtensionMethods.scala:102)
                at scala.reflect.api.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:1931)
                at scala.reflect.api.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:1929)
                at scala.collection.immutable.List.loop$1(List.scala:164)
                at scala.collection.immutable.List.mapConserve(List.scala:180)
                at scala.reflect.api.Trees$Transformer.transformStats(Trees.scala:1929)
                at scala.tools.nsc.transform.ExtensionMethods$Extender.transformStats(ExtensionMethods.scala:188)
                at scala.tools.nsc.transform.ExtensionMethods$Extender.transformStats(ExtensionMethods.scala:102)
                at scala.reflect.internal.Trees$$anonfun$itransform$7.apply(Trees.scala:1256)
                at scala.reflect.internal.Trees$$anonfun$itransform$7.apply(Trees.scala:1256)
                at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:1938)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:34)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:28)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:19)
                at scala.reflect.internal.Trees$class.itransform(Trees.scala:1255)
                at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:12)
                at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:12)
                at scala.reflect.api.Trees$Transformer.transform(Trees.scala:1910)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.scala$tools$nsc$transform$TypingTransformers$TypingTransformer$$super$transform(TypingTransformers.scala:44)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$2.apply(TypingTransformers.scala:46)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$2.apply(TypingTransformers.scala:46)
                at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:1938)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:34)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:28)
                at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:46)
                at scala.tools.nsc.transform.ExtensionMethods$Extender.transform(ExtensionMethods.scala:183)
                at scala.tools.nsc.transform.ExtensionMethods$Extender.transform(ExtensionMethods.scala:102)
                at scala.tools.nsc.ast.Trees$Transformer.transformUnit(Trees.scala:227)
                at scala.tools.nsc.transform.Transform$Phase.apply(Transform.scala:30)
                at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:461)
                at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:428)
                at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:428)
                at scala.collection.Iterator$class.foreach(Iterator.scala:727)
                at scala.collection.AbstractIterator.foreach(Iterator.scala:1156)
                at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:428)
                at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1574)
                at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1548)
                at scala.tools.nsc.Global$Run.compileSources(Global.scala:1544)
                at scala.tools.nsc.Global$Run.compile(Global.scala:1654)
                at scala.tools.nsc.Driver.doCompile(Driver.scala:33)
                at scala.tools.nsc.Main$.doCompile(Main.scala:79)
                at scala.tools.nsc.Driver.process(Driver.scala:54)
                at scala.tools.nsc.Driver.main(Driver.scala:67)
                at scala.tools.nsc.Main.main(Main.scala)
        
        Show
        Eugene Burmako added a comment - Here's a different error if one compiles a macro and its usage separately: C:\Projects\Kepler\sandbox @ topic/paramss>myke run . error: while compiling: Test_2.scala during phase: extmethods library version: version 2.10.0-20121007-121305-65ed97ed55 compiler version: version 2.10.0-20121007-121305-65ed97ed55 reconstructed args: -language:experimental.macros last tree to typer: This(class Ops) symbol: class Ops (flags: final) symbol definition: final class Ops[T] extends AnyVal tpe: Ops[T] symbol owners: class Ops -> package <empty> context owners: macro method f -> class Ops -> package <empty> == Enclosing template or block == Apply( // final def extension$f[T]($this: Ops[T]): Unit in object Ops TypeApply( // final def extension$f[T]($this: Ops[T]): Unit in object Ops, tree.tpe=($this: Ops[T])Unit "Ops"."extension$f" // final def extension$f[T]($this: Ops[T]): Unit in object Ops, tree.tpe=[T]($this: Ops[T])Unit <tpt> // tree.tpe=T ) This("Ops")final class Ops[T] extends AnyVal, tree.tpe=Ops[T] ) == Expanded type of tree == TypeRef( TypeSymbol(final class Ops[T] extends AnyVal) args = List(TypeParamTypeRef(TypeParam(T))) ) uncaught exception during compilation: scala.reflect.internal.Types$TypeError error: scala.reflect.internal.Types$TypeError: exception during macro expansion: java.lang.IllegalArgumentException: wrong number of arguments at scala.tools.nsc.typechecker.Contexts$Context.error(Contexts.scala:403) at scala.tools.nsc.typechecker.ContextErrors$TyperContextErrors$TyperErrorGen$.macroExpansionError(ContextErrors.scala:680) at scala.tools.nsc.typechecker.ContextErrors$TyperContextErrors$TyperErrorGen$.MacroGeneratedException(ContextErrors.scala:739) at scala.tools.nsc.typechecker.Macros$class.liftedTree1$1(Macros.scala:791) at scala.tools.nsc.typechecker.Macros$class.scala$tools$nsc$typechecker$Macros$$macroExpandWithRuntime(Macros.scala:768) at scala.tools.nsc.typechecker.Macros$$anonfun$scala$tools$nsc$typechecker$Macros$$macroExpand1$1.apply(Macros.scala:741) at scala.tools.nsc.typechecker.Macros$$anonfun$scala$tools$nsc$typechecker$Macros$$macroExpand1$1.apply(Macros.scala:732) at scala.tools.nsc.Global.withInfoLevel(Global.scala:189) at scala.tools.nsc.typechecker.Macros$class.scala$tools$nsc$typechecker$Macros$$macroExpand1(Macros.scala:732) at scala.tools.nsc.typechecker.Macros$class.macroExpand(Macros.scala:697) at scala.tools.nsc.Global$$anon$1.macroExpand(Global.scala:490) at scala.tools.nsc.typechecker.Typers$Typer.adapt(Typers.scala:1115) at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5448) at scala.tools.nsc.typechecker.Typers$Typer.typed(Typers.scala:5490) at scala.tools.nsc.typechecker.Typers$Typer.typedPos(Typers.scala:5494) at scala.tools.nsc.transform.ExtensionMethods$Extender$$anonfun$9.apply(ExtensionMethods.scala:175) at scala.tools.nsc.transform.ExtensionMethods$Extender$$anonfun$9.apply(ExtensionMethods.scala:175) at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:1938) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:34) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:28) at scala.tools.nsc.transform.ExtensionMethods$Extender.transform(ExtensionMethods.scala:174) at scala.tools.nsc.transform.ExtensionMethods$Extender.transform(ExtensionMethods.scala:102) at scala.reflect.api.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:1931) at scala.reflect.api.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:1929) at scala.collection.immutable.List.loop$1(List.scala:164) at scala.collection.immutable.List.mapConserve(List.scala:180) at scala.reflect.api.Trees$Transformer.transformStats(Trees.scala:1929) at scala.tools.nsc.transform.ExtensionMethods$Extender.transformStats(ExtensionMethods.scala:188) at scala.tools.nsc.transform.ExtensionMethods$Extender.transformStats(ExtensionMethods.scala:102) at scala.reflect.internal.Trees$class.itransform(Trees.scala:1234) at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:12) at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:12) at scala.reflect.api.Trees$Transformer.transform(Trees.scala:1910) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.scala$tools$nsc$transform$TypingTransformers$TypingTransformer$$super$transform(TypingTransformers.scala:44) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$1.apply(TypingTransformers.scala:44) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$1.apply(TypingTransformers.scala:44) at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:1938) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:34) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:28) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:44) at scala.tools.nsc.transform.ExtensionMethods$Extender.transform(ExtensionMethods.scala:144) at scala.tools.nsc.transform.ExtensionMethods$Extender.transform(ExtensionMethods.scala:102) at scala.reflect.api.Trees$Transformer.transformTemplate(Trees.scala:1915) at scala.reflect.internal.Trees$$anonfun$itransform$4.apply(Trees.scala:1238) at scala.reflect.internal.Trees$$anonfun$itransform$4.apply(Trees.scala:1237) at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:1938) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:34) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:28) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:19) at scala.reflect.internal.Trees$class.itransform(Trees.scala:1236) at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:12) at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:12) at scala.reflect.api.Trees$Transformer.transform(Trees.scala:1910) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:48) at scala.tools.nsc.transform.ExtensionMethods$Extender.transform(ExtensionMethods.scala:183) at scala.tools.nsc.transform.ExtensionMethods$Extender.transform(ExtensionMethods.scala:102) at scala.reflect.api.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:1931) at scala.reflect.api.Trees$Transformer$$anonfun$transformStats$1.apply(Trees.scala:1929) at scala.collection.immutable.List.loop$1(List.scala:164) at scala.collection.immutable.List.mapConserve(List.scala:180) at scala.reflect.api.Trees$Transformer.transformStats(Trees.scala:1929) at scala.tools.nsc.transform.ExtensionMethods$Extender.transformStats(ExtensionMethods.scala:188) at scala.tools.nsc.transform.ExtensionMethods$Extender.transformStats(ExtensionMethods.scala:102) at scala.reflect.internal.Trees$$anonfun$itransform$7.apply(Trees.scala:1256) at scala.reflect.internal.Trees$$anonfun$itransform$7.apply(Trees.scala:1256) at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:1938) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:34) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:28) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:19) at scala.reflect.internal.Trees$class.itransform(Trees.scala:1255) at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:12) at scala.reflect.internal.SymbolTable.itransform(SymbolTable.scala:12) at scala.reflect.api.Trees$Transformer.transform(Trees.scala:1910) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.scala$tools$nsc$transform$TypingTransformers$TypingTransformer$$super$transform(TypingTransformers.scala:44) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$2.apply(TypingTransformers.scala:46) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer$$anonfun$transform$2.apply(TypingTransformers.scala:46) at scala.reflect.api.Trees$Transformer.atOwner(Trees.scala:1938) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:34) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.atOwner(TypingTransformers.scala:28) at scala.tools.nsc.transform.TypingTransformers$TypingTransformer.transform(TypingTransformers.scala:46) at scala.tools.nsc.transform.ExtensionMethods$Extender.transform(ExtensionMethods.scala:183) at scala.tools.nsc.transform.ExtensionMethods$Extender.transform(ExtensionMethods.scala:102) at scala.tools.nsc.ast.Trees$Transformer.transformUnit(Trees.scala:227) at scala.tools.nsc.transform.Transform$Phase.apply(Transform.scala:30) at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:461) at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:428) at scala.tools.nsc.Global$GlobalPhase$$anonfun$run$1.apply(Global.scala:428) at scala.collection.Iterator$class.foreach(Iterator.scala:727) at scala.collection.AbstractIterator.foreach(Iterator.scala:1156) at scala.tools.nsc.Global$GlobalPhase.run(Global.scala:428) at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1574) at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1548) at scala.tools.nsc.Global$Run.compileSources(Global.scala:1544) at scala.tools.nsc.Global$Run.compile(Global.scala:1654) at scala.tools.nsc.Driver.doCompile(Driver.scala:33) at scala.tools.nsc.Main$.doCompile(Main.scala:79) at scala.tools.nsc.Driver.process(Driver.scala:54) at scala.tools.nsc.Driver.main(Driver.scala:67) at scala.tools.nsc.Main.main(Main.scala)
        Show
        Eugene Burmako added a comment - https://github.com/scala/scala/pull/1474
        Show
        Eugene Burmako added a comment - Fixed in https://github.com/scala/scala/commit/0bf9daaac7ab46a3e9dd113565b0073eed95be59

          People

          • Assignee:
            Eugene Burmako
            Reporter:
            Paul Phillips
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development