Details

      Description

      build.sbt

      scalacOptions += "-Ywarn-unused-import"
       
      libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value
       
      scalaVersion := "2.11.8"
      

      Macro.scala

      package com.example
       
      import scala.reflect.macros.blackbox.Context
      import scala.language.experimental.macros
       
      object Macro {
        def foo: Int = macro fooImpl
        def fooImpl(c: Context): c.Tree = {
          import c.universe._
       
          q"""
           import scala.util.Random
           42
          """
        }
      }
      

      REPL

      Welcome to Scala 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_92).
      Type in expressions for evaluation. Or try :help.
       
      scala> com.example.Macro.foo
      java.lang.ArrayIndexOutOfBoundsException: 182
              at scala.reflect.internal.util.InternalPositionImpl$class.calculateColumn(Position.scala:211)
              at scala.reflect.internal.util.InternalPositionImpl$class.column(Position.scala:167)
              at scala.reflect.internal.util.Position.column(Position.scala:12)
              at scala.reflect.internal.util.InternalPositionImpl$class.lineCaret(Position.scala:169)
              at scala.reflect.internal.util.Position.lineCaret(Position.scala:12)
              at scala.reflect.internal.util.InternalPositionImpl$class.indicator$1(Position.scala:186)
              at scala.reflect.internal.util.InternalPositionImpl$class.errorAt$1(Position.scala:187)
              at scala.reflect.internal.util.InternalPositionImpl$class.showError(Position.scala:192)
              at scala.reflect.internal.util.Position.showError(Position.scala:12)
              at scala.reflect.internal.util.Position$.formatMessage(Position.scala:42)
              at scala.tools.nsc.reporters.ConsoleReporter.printMessage(ConsoleReporter.scala:50)
              at scala.tools.nsc.interpreter.ReplReporter.print(ReplReporter.scala:50)
              at scala.tools.nsc.reporters.ConsoleReporter.display(ConsoleReporter.scala:69)
              at scala.tools.nsc.reporters.AbstractReporter.info0(AbstractReporter.scala:48)
              at scala.tools.nsc.reporters.AbstractReporter.info0(AbstractReporter.scala:16)
              at scala.reflect.internal.Reporter.warning(Reporting.scala:81)
              at scala.tools.nsc.interpreter.ReplReporter.scala$tools$nsc$interpreter$ReplReporter$$super$warning(ReplReporter.scala:32)
              at scala.tools.nsc.interpreter.ReplReporter$$anonfun$warning$1.apply(ReplReporter.scala:32)
              at scala.tools.nsc.interpreter.ReplReporter$$anonfun$warning$1.apply(ReplReporter.scala:32)
              at scala.tools.nsc.interpreter.ReplReporter.withoutTruncating(ReplReporter.scala:28)
              at scala.tools.nsc.interpreter.ReplReporter.warning(ReplReporter.scala:32)
              at scala.tools.nsc.typechecker.Contexts$class.warnUnusedImports(Contexts.scala:64)
              at scala.tools.nsc.interpreter.ReplGlobal$$anon$1.warnUnusedImports(ReplGlobal.scala:23)
              at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:106)
              at scala.tools.nsc.Global$GlobalPhase$$anonfun$applyPhase$1.apply$mcV$sp(Global.scala:440)
              at scala.tools.nsc.Global$GlobalPhase.withCurrentUnit(Global.scala:431)
              at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:440)
              at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:94)
              at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:93)
              at scala.collection.Iterator$class.foreach(Iterator.scala:893)
              at scala.collection.AbstractIterator.foreach(Iterator.scala:1336)
              at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:93)
              at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1501)
              at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1486)
              at scala.tools.nsc.Global$Run.compileSources(Global.scala:1481)
              at scala.tools.nsc.interpreter.IMain.compileSourcesKeepingRun(IMain.scala:435)
              at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compileAndSaveRun(IMain.scala:855)
              at scala.tools.nsc.interpreter.IMain$ReadEvalPrint.compile(IMain.scala:813)
              at scala.tools.nsc.interpreter.IMain$Request.compile$lzycompute(IMain.scala:1002)
              at scala.tools.nsc.interpreter.IMain$Request.compile(IMain.scala:997)
              at scala.tools.nsc.interpreter.IMain.compile(IMain.scala:579)
              at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:567)
              at scala.tools.nsc.interpreter.IMain.interpret(IMain.scala:565)
              at scala.tools.nsc.interpreter.ILoop.interpretStartingWith(ILoop.scala:807)
              at scala.tools.nsc.interpreter.ILoop.command(ILoop.scala:681)
              at scala.tools.nsc.interpreter.ILoop.processLine(ILoop.scala:395)
              at scala.tools.nsc.interpreter.ILoop.loop(ILoop.scala:415)
              at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply$mcZ$sp(ILoop.scala:923)
              at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:909)
              at scala.tools.nsc.interpreter.ILoop$$anonfun$process$1.apply(ILoop.scala:909)
              at scala.reflect.internal.util.ScalaClassLoader$.savingContextLoader(ScalaClassLoader.scala:97)
              at scala.tools.nsc.interpreter.ILoop.process(ILoop.scala:909)
              at scala.tools.nsc.interpreter.ILoop.main(ILoop.scala:934)
              at xsbt.ConsoleInterface.run(ConsoleInterface.scala:62)
              at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
              at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
              at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
              at java.lang.reflect.Method.invoke(Method.java:498)
              at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:101)
              at sbt.compiler.AnalyzingCompiler.console(AnalyzingCompiler.scala:76)
              at sbt.Console.sbt$Console$$console0$1(Console.scala:22)
              at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply$mcV$sp(Console.scala:23)
              at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply(Console.scala:23)
              at sbt.Console$$anonfun$apply$2$$anonfun$apply$1.apply(Console.scala:23)
              at sbt.Logger$$anon$4.apply(Logger.scala:84)
              at sbt.TrapExit$App.run(TrapExit.scala:248)
              at java.lang.Thread.run(Thread.java:745)
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                apm A. P. Marki
                Reporter:
                kenji yoshida kenji yoshida
              • Votes:
                1 Vote for this issue
                Watchers:
                6 Start watching this issue

                Dates

                • Created:
                  Updated: