Macro annotations not working

347 views
Skip to first unread message

Simon Schäfer

unread,
Mar 4, 2013, 6:12:08 AM3/4/13
to scala...@googlegroups.com
I tried to use macro example at: http://scalamacros.org/news/2013/02/19/macro-annotations-and-call-for-ideas.html

But I get an error:

[error] /home/antoras/dev/Scala/sbt-example-paradise/macros/src/main/scala/macrotest/Macros.scala:127: value introduceMember is not a member of scala.reflect.macros.Context
[error]     c.introduceMember(targetType.typeSymbol, method)
[error]       ^

I used the sbt configuration of https://github.com/scalamacros/sbt-example-paradise

Do I need to update something in sbt or is the macro version mentioned in the link above not yet deployed?

Greetings,
Simon

Eugene Burmako

unread,
Mar 4, 2013, 6:16:04 AM3/4/13
to Simon Schäfer, scala-user
For now I'm keeping c.introduceMember in a separate branch: https://github.com/scalamacros/kepler/tree/topic/introduce-member, as it entails a controversial refactoring of template typechecking.

You could either build that branch yourself or I could build it for you and upload it to my dropbox. Then using it in sbt is as simple as setting scalaHome in the SBT build script.



--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Simon Schäfer

unread,
Mar 4, 2013, 6:33:09 AM3/4/13
to scala-user
Hi Eugene,

I'm building your branch right now. Can you just tell me how I can use it in sbt once it is finished? Which parts of the config do I need to change?

Eugene Burmako

unread,
Mar 4, 2013, 6:38:45 AM3/4/13
to Simon Schäfer, scala-user

Simon Schäfer

unread,
Mar 4, 2013, 7:08:37 AM3/4/13
to scala-user
I added scalaHome and unmanagedBase to my build configuration:

  val buildSettings = Defaults.defaultSettings ++ Seq(
    organization := "org.scalamacros",
    version := "1.0.0",
    scalacOptions ++= Seq(
      "-deprecation",
      "-feature",
      "-unchecked",
      "-Xlint",
      "-Xlog-reflective-calls",
      "-Ywarn-adapted-args",
      "-encoding", "UTF-8",
      "-target:jvm-1.6",
      "-Ymacro-debug-lite"
    ),
    scalaHome := Some(file("/home/antoras/dev/Scala/scala/build/pack")),
    unmanagedBase := file("/home/antoras/dev/Scala/scala/build/pack"),
    scalaVersion := "2.11.0-SNAPSHOT",
    scalaOrganization := "org.scala-lang.macro-paradise",
    resolvers += Resolver.sonatypeRepo("snapshots")
  )

Furthermore I changed the sbt project "macros":

  lazy val macros: Project = Project(
    "macros",
    file("macros"),
    settings = buildSettings ++ Seq(
      //libraryDependencies <+= (scalaVersion)("org.scala-lang.macro-paradise" % "scala-reflect" % _))
      libraryDependencies <+= (scalaVersion)("org.scala-lang" % "scala-reflect" % _))
  )

The project is updated correctly at it seems, but the code doesn't compile anymore:

[info] Compiling 1 Scala source to /home/antoras/dev/Scala/sbt-example-paradise/macros/target/scala-2.11/classes...
[error]
[error]      while compiling: /home/antoras/dev/Scala/sbt-example-paradise/macros/src/main/scala/macrotest/Macros.scala
[error]         during phase: typer
[error]      library version: version 2.11.0-20130223-173205-ef24a8b53c
[error]     compiler version: version 2.11.0-20130223-173205-ef24a8b53c
[error]   reconstructed args: -Ymacro-debug-lite -Ywarn-nullary-unit -feature -Xlint -Ywarn-inaccessible -classpath /home/antoras/dev/Scala/sbt-example-paradise/macros/target/scala-2.11/classes:/home/antoras/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.11.0-SNAPSHOT.jar -unchecked -bootclasspath /usr/lib/jvm/java-6-openjdk/jre/lib/resources.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/rt.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/sunrsasign.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/jsse.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/jce.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/charsets.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/netx.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/plugin.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/rhino.jar:/usr/lib/jvm/java-6-openjdk/jre/lib/modules/jdk.boot.jar:/usr/lib/jvm/java-6-openjdk/jre/classes:/home/antoras/dev/Scala/scala/build/pack/lib/scala-library.jar -deprecation -Xlog-reflective-calls -d /home/antoras/dev/Scala/sbt-example-paradise/macros/target/scala-2.11/classes -Ywarn-nullary-override -Ywarn-infer-any -Ywarn-adapted-args
[error]
[error]   last tree to typer: TypeTree(class C)
[error]               symbol: class C in package macrotest (flags: )
[error]    symbol definition: class C extends AnyRef
[error]                  tpe: macrotest.C
[error]        symbol owners: class C -> package macrotest
[error]       context owners: constructor C -> class C -> package macrotest
[error]
[error] == Enclosing template or block ==
[error]
[error] DefDef( // def <init>: <?> in class C
[error]   <method>
[error]   "<init>"
[error]   []
[error]   List(Nil)
[error]   <tpt> // tree.tpe=macrotest.C
[error]   Block(
[error]     Apply(
[error]       super."<init>"
[error]       Nil
[error]     )
[error]     ()
[error]   )
[error] )
[error]
[error] == Expanded type of tree ==
[error]
[error] TypeRef(TypeSymbol(class C extends AnyRef))
[error]
[error] uncaught exception during compilation: FatalError("class Universe does not have a member Quasiquote") @ scala.reflect.internal.Definitions$DefinitionsClass.scala$reflect$internal$Definitions$DefinitionsClass$$fatalMissingSymbol(Definitions.scala:996)
[trace] Stack trace suppressed: run last macros/compile:compile for the full output.
[error] (macros/compile:compile) scala.reflect.internal.FatalError: class Universe does not have a member Quasiquote
[error] Total time: 2 s, completed Mar 4, 2013 1:06:08 PM

Eugene Burmako

unread,
Mar 4, 2013, 7:09:24 AM3/4/13
to Simon Schäfer, scala-user
Try sbt "reboot full"

Simon Schäfer

unread,
Mar 4, 2013, 8:52:27 AM3/4/13
to scala-user
I tried to get it to work with unmanagedJars but because I have no idea what this config is doing I have no idea if I have built it up correctly:

https://gist.github.com/sschaef/5082357

Do I need to mention config("macro") (L24) somewhere else beside of buildSettings or project macros (L40)?

On 03/04/2013 01:28 PM, Eugene Burmako wrote:
The crash indicates that you're using an incompatible version of scala-reflect.jar. /home/antoras/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.11.0-SNAPSHOT.jar in the error message is the culprit.

What if you try to fiddle with unmanagedJars as they do in Slick: https://github.com/slick/slick/blob/master/project/Build.scala?


On 4 March 2013 13:19, Simon Schäfer <ma...@antoras.de> wrote:
I did but no change. I tried it in sbt12+sbt13, but neither worked.

Eugene Burmako

unread,
Mar 4, 2013, 8:58:12 AM3/4/13
to Simon Schäfer, Christopher Vogt, Stefan Zeiger, scala-user
Chris, Stefan, could you please take a look?

Stefan Zeiger

unread,
Mar 4, 2013, 9:19:57 AM3/4/13
to scala...@googlegroups.com
On 2013-03-04 14:58, Eugene Burmako wrote:
Chris, Stefan, could you please take a look?


On 4 March 2013 14:52, Simon Schäfer <ma...@antoras.de> wrote:
I tried to get it to work with unmanagedJars but because I have no idea what this config is doing I have no idea if I have built it up correctly:

https://gist.github.com/sschaef/5082357

Do I need to mention config("macro") (L24) somewhere else beside of buildSettings or project macros (L40)?

Forget the macro config, that's a separate config (besides main and test) used by the main Slick project to compile the macros (in src/macro/scala) first. Getting these more complex sbt configurations to work is frequently a matter of trial & error for me (or asking Mark Harrah for help). In your previous version, the dependency on scala-reflect with the standard groupId looks wrong. I think you need to get rid of that and replace it with unmanaged dependencies to the JAR files.

-sz

Simon Schäfer

unread,
Mar 4, 2013, 10:19:05 AM3/4/13
to scala-user
Thanks Stefan, unmanaged dependencies did the trick. The config file now looks like this:

https://gist.github.com/sschaef/5082357

Nevertheless, I get another error now. It seems to be something about the internals of scala-reflect:

https://gist.github.com/sschaef/5082930

Eugene, could you please take another look?
--
You received this message because you are subscribed to a topic in the Google Groups "scala-user" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/scala-user/yeXN_pGuYjE/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to scala-user+...@googlegroups.com.

Eugene Burmako

unread,
Mar 4, 2013, 10:21:23 AM3/4/13
to Simon Schäfer, scala-user
That might be a bug I introduced when implementing introduceMember. Could you please publish the code which causes the crash?


--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+...@googlegroups.com.

Simon Schäfer

unread,
Mar 4, 2013, 11:26:09 AM3/4/13
to scala-user
I found out that the problem lies at a different place. introduceMember works fine now. Thanks for implementing it.

I didn't look yet in detail to the macro implementation and where the problem is, just for reference:

The problem occurs here: https://github.com/sschaef/sbt-example-paradise/blob/master/core/src/main/scala/macrouse/Test.scala#L28

Whenever I try to use the lines that are commented out I get a crash. The code shown in comments below is generated. The macro implementation: https://github.com/sschaef/sbt-example-paradise/blob/master/macros/src/main/scala/macrotest/Macros.scala#L83

Eugene Burmako

unread,
Mar 4, 2013, 11:32:52 AM3/4/13
to Simon Schäfer, scala-user
Does it crash in 2.10.x?

Simon Schäfer

unread,
Mar 4, 2013, 11:54:18 AM3/4/13
to Eugene Burmako, scala-user
Do you mean changing scalaVersion to 2.10.x? If yes, then it doesn't work either (I tried 2.10.0 and 2.10.1). The same error messages.

Eugene Burmako

unread,
Mar 4, 2013, 12:06:02 PM3/4/13
to Simon Schäfer, scala-user
I think scalaVersion only takes effect if you remove all build customizations such as localHome.

Simon Schäfer

unread,
Mar 4, 2013, 12:30:30 PM3/4/13
to scala...@googlegroups.com
When I remove scalaHome option everything works fine (with exception of
introduceMember).

On Mon 04 Mar 2013 06:06:02 PM CET, Eugene Burmako wrote:
> I think scalaVersion only takes effect if you remove all build
> customizations such as localHome.
>
>
> On 4 March 2013 17:54, Simon Schäfer <ma...@antoras.de
> <mailto:ma...@antoras.de>> wrote:
>
> Do you mean changing scalaVersion to 2.10.x? If yes, then it
> doesn't work either (I tried 2.10.0 and 2.10.1). The same error
> messages.
>
>
> On 03/04/2013 05:32 PM, Eugene Burmako wrote:
>> Does it crash in 2.10.x?
>>
>>
>> On 4 March 2013 17:26, Simon Schäfer <ma...@antoras.de
>> <mailto:ma...@antoras.de>> wrote:
>>
>> I found out that the problem lies at a different place.
>> introduceMember works fine now. Thanks for implementing it.
>>
>> I didn't look yet in detail to the macro implementation and
>> where the problem is, just for reference:
>>
>> The problem occurs here:
>> https://github.com/sschaef/sbt-example-paradise/blob/master/core/src/main/scala/macrouse/Test.scala#L28
>>
>> Whenever I try to use the lines that are commented out I get
>> a crash. The code shown in comments below is generated. The
>> macro implementation:
>> https://github.com/sschaef/sbt-example-paradise/blob/master/macros/src/main/scala/macrotest/Macros.scala#L83
>>
>>
>> On 03/04/2013 04:21 PM, Eugene Burmako wrote:
>>> That might be a bug I introduced when implementing
>>> introduceMember. Could you please publish the code which
>>> causes the crash?
>>>
>>>
>>> On 4 March 2013 16:19, Simon Schäfer <ma...@antoras.de
>>> <mailto:ma...@antoras.de>> wrote:
>>>
>>> Thanks Stefan, unmanaged dependencies did the trick. The
>>> config file now looks like this:
>>>
>>> https://gist.github.com/sschaef/5082357
>>>
>>> Nevertheless, I get another error now. It seems to be
>>> something about the internals of scala-reflect:
>>>
>>> https://gist.github.com/sschaef/5082930
>>>
>>> Eugene, could you please take another look?
>>>
>>>
>>> On 03/04/2013 03:19 PM, Stefan Zeiger wrote:
>>>> On 2013-03-04 14:58, Eugene Burmako wrote:
>>>>> Chris, Stefan, could you please take a look?
>>>>>
>>>>>
>>>>> On 4 March 2013 14:52, Simon Schäfer <ma...@antoras.de
>>>> <mailto:scala-user+...@googlegroups.com>.
>>>> For more options, visit
>>>> https://groups.google.com/groups/opt_out.
>>>>
>>>>
>>>
>>> --
>>> You received this message because you are subscribed to
>>> the Google Groups "scala-user" group.
>>> To unsubscribe from this group and stop receiving emails
>>> from it, send an email to
>>> scala-user+...@googlegroups.com
>>> <mailto:scala-user%2Bunsu...@googlegroups.com>.
>>> For more options, visit
>>> https://groups.google.com/groups/opt_out.
>>>
>>>
>>>
>>
>> --
>> You received this message because you are subscribed to the
>> Google Groups "scala-user" group.
>> To unsubscribe from this group and stop receiving emails from
>> it, send an email to scala-user+...@googlegroups.com
>> <mailto:scala-user%2Bunsu...@googlegroups.com>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>>
>>
>
> --
> You received this message because you are subscribed to the Google
> Groups "scala-user" group.
> To unsubscribe from this group and stop receiving emails from it,
> send an email to scala-user+...@googlegroups.com
> <mailto:scala-user%2Bunsu...@googlegroups.com>.

Eugene Burmako

unread,
Mar 4, 2013, 2:03:42 PM3/4/13
to Simon Schäfer, scala-user
Yep, then it's me breaking something when refactoring the typer for introduceMember. I'll try to take a look soon.


            an email to scala-user+unsubscribe@googlegroups.com
            <mailto:scala-user+unsub...@googlegroups.com>.

            For more options, visit
            https://groups.google.com/groups/opt_out.



            --
            You received this message because you are subscribed to
            the Google Groups "scala-user" group.
            To unsubscribe from this group and stop receiving emails
            from it, send an email to

            <mailto:scala-user%2Bunsu...@googlegroups.com>.
            For more options, visit
            https://groups.google.com/groups/opt_out.




        --
        You received this message because you are subscribed to the
        Google Groups "scala-user" group.
        To unsubscribe from this group and stop receiving emails from
        it, send an email to scala-user+unsubscribe@googlegroups.com

        <mailto:scala-user%2Bunsu...@googlegroups.com>.
        For more options, visit https://groups.google.com/groups/opt_out.




    --
    You received this message because you are subscribed to the Google
    Groups "scala-user" group.
    To unsubscribe from this group and stop receiving emails from it,

--
You received this message because you are subscribed to a topic in the
Google Groups "scala-user" group.
To unsubscribe from this topic, visit
https://groups.google.com/d/topic/scala-user/yeXN_pGuYjE/unsubscribe?hl=en.
To unsubscribe from this group and all its topics, send an email to

For more options, visit https://groups.google.com/groups/opt_out.



--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scala-user+unsubscribe@googlegroups.com.

Eugene Burmako

unread,
Mar 9, 2013, 8:00:31 AM3/9/13
to scala-user
Hey, sorry for taking so long! Is this a blocker for you? If yes, I
could take a look this weekend, otherwise I'd prefer to do that later.

On Mar 4, 6:30 pm, Simon Schäfer <m...@antoras.de> wrote:
> When I remove scalaHome option everything works fine (with exception of
> introduceMember).
>
> On Mon 04 Mar 2013 06:06:02 PM CET, Eugene Burmako wrote:
>
>
>
>
>
>
>
> > I think scalaVersion only takes effect if you remove all build
> > customizations such as localHome.
>
> > On 4 March 2013 17:54, Simon Schäfer <m...@antoras.de
> > <mailto:m...@antoras.de>> wrote:
>
> >     Do you mean changing scalaVersion to 2.10.x? If yes, then it
> >     doesn't work either (I tried 2.10.0 and 2.10.1). The same error
> >     messages.
>
> >     On 03/04/2013 05:32 PM, Eugene Burmako wrote:
> >>     Does it crash in 2.10.x?
>
> >>     On 4 March 2013 17:26, Simon Schäfer <m...@antoras.de
> >>     <mailto:m...@antoras.de>> wrote:
>
> >>         I found out that the problem lies at a different place.
> >>         introduceMember works fine now. Thanks for implementing it.
>
> >>         I didn't look yet in detail to the macro implementation and
> >>         where the problem is, just for reference:
>
> >>         The problem occurs here:
> >>        https://github.com/sschaef/sbt-example-paradise/blob/master/core/src/...
>
> >>         Whenever I try to use the lines that are commented out I get
> >>         a crash. The code shown in comments below is generated. The
> >>         macro implementation:
> >>        https://github.com/sschaef/sbt-example-paradise/blob/master/macros/sr...
>
> >>         On 03/04/2013 04:21 PM, Eugene Burmako wrote:
> >>>         That might be a bug I introduced when implementing
> >>>         introduceMember. Could you please publish the code which
> >>>         causes the crash?
>
> >>>         On 4 March 2013 16:19, Simon Schäfer <m...@antoras.de
> >>>         <mailto:m...@antoras.de>> wrote:
>
> >>>             Thanks Stefan, unmanaged dependencies did the trick. The
> >>>             config file now looks like this:
>
> >>>            https://gist.github.com/sschaef/5082357
>
> >>>             Nevertheless, I get another error now. It seems to be
> >>>             something about the internals of scala-reflect:
>
> >>>            https://gist.github.com/sschaef/5082930
>
> >>>             Eugene, could you please take another look?
>
> >>>             On 03/04/2013 03:19 PM, Stefan Zeiger wrote:
> >>>>             On 2013-03-04 14:58, Eugene Burmako wrote:
> >>>>>             Chris, Stefan, could you please take a look?
>
> >>>>>             On 4 March 2013 14:52, Simon Schäfer <m...@antoras.de
> >>>>>             <mailto:m...@antoras.de>> wrote:
>
> >>>>>                 I tried to get it to work with unmanagedJars but
> >>>>>                 because I have no idea what this config is doing I
> >>>>>                 have no idea if I have built it up correctly:
>
> >>>>>                https://gist.github.com/sschaef/5082357
>
> >>>>>                 Do I need to mention config("macro") (L24)
> >>>>>                 somewhere else beside of buildSettings or project
> >>>>>                 macros (L40)?
>
> >>>>             Forget the macro config, that's a separate config
> >>>>             (besides main and test) used by the main Slick project
> >>>>             to compile the macros (in src/macro/scala) first.
> >>>>             Getting these more complex sbt configurations to work
> >>>>             is frequently a matter of trial & error for me (or
> >>>>             asking Mark Harrah for help). In your previous version,
> >>>>             the dependency on scala-reflect with the standard
> >>>>             groupId looks wrong. I think you need to get rid of
> >>>>             that and replace it with unmanaged dependencies to the
> >>>>             JAR files.
>
> >>>>             -sz
> >>>>             --
> >>>>             You received this message because you are subscribed to
> >>>>             a topic in the Google Groups "scala-user" group.
> >>>>             To unsubscribe from this topic, visit
> >>>>            https://groups.google.com/d/topic/scala-user/yeXN_pGuYjE/unsubscribe?....
> >>>>             To unsubscribe from this group and all its topics, send
> >>>>             an email to scala-user+...@googlegroups.com
> >>>>             <mailto:scala-user+...@googlegroups.com>.
> >>>>             For more options, visit
> >>>>            https://groups.google.com/groups/opt_out.
>
> >>>             --
> >>>             You received this message because you are subscribed to
> >>>             the Google Groups "scala-user" group.
> >>>             To unsubscribe from this group and stop receiving emails
> >>>             from it, send an email to
> >>>             scala-user+...@googlegroups.com
> >>>             <mailto:scala-user%2Bunsu...@googlegroups.com>.
> >>>             For more options, visit
> >>>            https://groups.google.com/groups/opt_out.
>
> >>         --
> >>         You received this message because you are subscribed to the
> >>         Google Groups "scala-user" group.
> >>         To unsubscribe from this group and stop receiving emails from
> >>         it, send an email to scala-user+...@googlegroups.com
> >>         <mailto:scala-user%2Bunsu...@googlegroups.com>.
> >>         For more options, visithttps://groups.google.com/groups/opt_out.
>
> >     --
> >     You received this message because you are subscribed to the Google
> >     Groups "scala-user" group.
> >     To unsubscribe from this group and stop receiving emails from it,
> >     send an email to scala-user+...@googlegroups.com
> >     <mailto:scala-user%2Bunsu...@googlegroups.com>.
> >     For more options, visithttps://groups.google.com/groups/opt_out.
>
> > --
> > You received this message because you are subscribed to a topic in the
> > Google Groups "scala-user" group.
> > To unsubscribe from this topic, visit
> >https://groups.google.com/d/topic/scala-user/yeXN_pGuYjE/unsubscribe?....

Simon Schäfer

unread,
Mar 9, 2013, 8:38:30 AM3/9/13
to Eugene Burmako, scala-user
Hi Eugene,

no it is not a problem. The code that fails is only used for debugging
output, thus I could comment it out easily to being able to still work
with your branch topc/introduce-member.
Reply all
Reply to author
Forward
0 new messages