Scala Programming Language
  1. Scala Programming Language
  2. SI-5753

macros cannot be loaded when inherited from a class or a trait

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Fixed
    • Affects Version/s: Scala 2.10.0-M3
    • Fix Version/s: Scala 2.10.0
    • Component/s: Macros
    • Labels:

      Description

      import scala.reflect.macros.Context
      import language.experimental.macros
      
      trait Impls {
        def impl(c: Context)(x: c.Expr[Any]) = x
      }
      
      object Macros extends Impls {
        def foo(x: Any) = macro impl
      }
      
      object Test extends App {
        import Macros._
        println(foo(42))
      }
      
      Macros_Test_2.scala:9: error: macro implementation not found: foo (the most common reason for that is that you cannot use macro implementations in the same compilation run that defines them)
      if you do need to define macro implementations along with the rest of your program, consider two-phase compilation with -Xmacro-fallback-classpath in the second phase pointing to the output of the first phase
        println(foo(42))
                   ^
      one error found
      

        Activity

        Hide
        Eugene Burmako added a comment - - edited

        Another manifestation:

        import scala.reflect.macros.Context
        import language.experimental.macros
        
        trait ImplContainer {
          object Impls {
            def foo(c: Context)(x: c.Expr[Any]) = x
          }
        }
        
        object Macros extends ImplContainer {
          def foo(x: Any) = macro Impls.foo
        }
        
        object Test extends App {
          import Macros._
          println(foo(42))
        }
        
        Show
        Eugene Burmako added a comment - - edited Another manifestation: import scala.reflect.macros.Context import language.experimental.macros trait ImplContainer { object Impls { def foo(c: Context)(x: c.Expr[Any]) = x } } object Macros extends ImplContainer { def foo(x: Any) = macro Impls.foo } object Test extends App { import Macros._ println(foo(42)) }
        Hide
        Eugene Burmako added a comment -

        The issue is being fixed.

        Show
        Eugene Burmako added a comment - The issue is being fixed.
        Hide
        Eugene Burmako added a comment - - edited

        There's no way for the original example to compile:

        import scala.reflect.makro.{Context => Ctx}
        
        trait Impls {
          def impl(c: Ctx)(x: c.Expr[Any]) = x
        }
        
        import scala.reflect.makro.{Context => Ctx}
        
        object Macros extends Impls {
          def foo(x: Any) = macro impl
        }
        
        object Test extends App {
          import Macros._
          println(foo(42))
        }
        

        Therefore I've updated the bug description with something legible. This one would make a nice test case, though.

        Show
        Eugene Burmako added a comment - - edited There's no way for the original example to compile: import scala.reflect.makro.{Context => Ctx} trait Impls { def impl(c: Ctx)(x: c.Expr[Any]) = x } import scala.reflect.makro.{Context => Ctx} object Macros extends Impls { def foo(x: Any) = macro impl } object Test extends App { import Macros._ println(foo(42)) } Therefore I've updated the bug description with something legible. This one would make a nice test case, though.
        Show
        Eugene Burmako added a comment - Fixed in https://github.com/scala/scala/commit/597a949e8700d585dc89979b66375367ac73acc2

          People

          • Assignee:
            Eugene Burmako
            Reporter:
            Eugene Burmako
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development