Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
    Todd O'Bryan
    If I have a question about reflection in 2.12.4, should I ask it here or in the scalamacros/scalamacros channel?
    Todd O'Bryan
    I guess I'll ask here. I'm getting an error "called constructor's definition must precede calling constructor's definition" which is coming from a constructor I'm trying to create in a macro. However, when I showCode(...) the class definition, it seems like everything should work:
    @PersistenceCapable(detachable = "true") class User private () {
      def this(id: Long, username: String, first: String, middle: String, last: String, preferred: String) = {
        _id = id;
        _username = username;
        _first = first;
        _middle = middle;
        _last = last;
        _preferred = preferred
      @PrimaryKey @Persistent(valueStrategy = IdGeneratorStrategy.INCREMENT) @jdoField @readOnly private[this] var id: Long = _;
      @Unique @jdoField private[this] var username: String = _;
      @jdoField private[this] var first: String = _;
      @jdoField private[this] var middle: Option[String] = _;
      @Column(length = 30) @jdoField private[this] var last: String = _;
      @jdoField private[this] var preferred: Option[String] = _;
      override def toString: String = StringContext("User(", " ", ")").s(id, formalName);
      def displayName: String = StringContext("", " ", "").s(preferred.getOrElse(first), last);
      def formalName: String = StringContext("", ", ", "", "").s(last, first, middle.map(((x$1) => " ".+(x$1))).getOrElse(""));
      def shortName: String = StringContext("", ", ", "").s(last, first.substring(0, 1))
    Note that I get the same error whether the constructor is before or after the field/methods declarations and whether or not I explicitly include a list of constructor params on the original class.
    Todd O'Bryan
    Actually, just realized that the part of the macro that changes the names of the fields by adding an underscore at the beginning isn't in there. Let me see if that changes anything.
    Todd O'Bryan
    OK. I've done more fiddling. If I filter out the default constructor from the classDef, I get an error saying that called constructor's definition must precede calling constructor's definition', but if I include it with..$stats, I get an error saying thatthis()` has been defined twice.
    Oron Port
    I suggest you print the tree and see what is going on. showCode and if that won't help than showRaw
    You have to add a position to a secondary constructor, apparently.
    Todd O'Bryan
    Welp, that fixed it.
    Todd O'Bryan
    Anybody know how I'd add private[this] to modifiers for a var declaration? mapAnnotations makes it really easy to create a new Modifiers instance based on a previous one annotations-wise, but I can't find something similar for flags and privateWithin...
    Todd O'Bryan
    For future reference, the only way I can figure out is, if mods is the old Modifiers, then Modifiers(mods.flags | Flag.TO_ADD, mods.privateWithin, mods.annotations).
    And I think the difference between private and private[this] is that the latter has the Flag.LOCAL set, but both have Flag.PRIVATE set and have an empty privateWithin value.
    Aldo Stracquadanio
    is it possible to use macroparadise to implement a def macro?
    I mean, with the capabilities of an annotation macro, i.e. receiving a non-typechecked tree as an input
    Oron Port
    Is there a way to get the number of extending classes of a sealed trait at compiler time?
    Jason Zaugg
    At what point during compile time? After typer it is easy, during typer it is hard to know if the list is complete yet.
    There is a mechanism to detect if you call it too early from a macro (scala/scala#5284)
    Oron Port
    I'm unsure. Will it be possible to do something like:
    sealed trait Foo
    final class Bar1 extends Foo
    final class Bar2 extends Foo
    def numOfBars(implicit g : ExtendingCount[Foo]) : Int = g.value
    Jason Zaugg
    The API, is Symbol. knownDirectSubclasses
    Oron Port
    Ok, I'll try it. Thanks
    I want to try and use the maximum enumeration count as a compile-time constraint on a parameter.
    Ferdinand Svehla
    Is the release for 2.12.6 planned for some time this week?
    Flavian Alexandru
    @fsvehla Sorry I replied on the wrong channel, confused notifications with one of my projects. If you got my last message I have no affiliation to the macro-paradise team and don’t know anything about their release schedule
    Bruno Bieth
    Hi, does the scalamacros paradise plugin supports the meta macro annotations?
    Is there a distribution of paradise plugin compiled for Scala 2.13.0-M4?
    Oron Port
    Paradise is built in that version and is enabled via compiler flag
    Thanks for clearing this! I spent quite some time thinking my compilation errors are caused by a missing JAR.

    HI guys
    I try compile


    With maven, my IDE Idea work fine.
    But maven give me error that no implicit found.
    it look like maven di not work with macros well
    I take maven plugins confg from official site

    [ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:4.1.1:testCompile (default) on project af-s3-spark_2.11: Execution default of goal net.alchim31.maven:scala-maven-plugin:4.1.1:testCompile failed.: CompileFailed -> [Help 1]
    Can some on help me configure maven to support macros.

    I'am also try to add


    in different scopes, but this not help
    But it does not help

    tanaka takaya
    Remy Willems
    Hi there, I have a question about Scala macro's. I'm using ScalaJS and am trying to replace some reflection code with macro's. In the reflection code, there was a trait Named that gave a class a name method based on reflecting on the Name of the inheriting class. Can I do something similar with macro's, where a def name method is generated for each classes that inherits from Named?
    Oron Port
    I'm not sure if it can be done like that because a macro needs a context to run. You can do something like:
    abstract class Named(implicit namer : Namer) {
      val name : String = namer.value
    class Foo extends Named //.name will be Foo
    class Bar extends Foo //.name will still be Foo
    Remy Willems
    Right, that makes sense, and I might approximate what I'm looking for with that, thanks :)
    I guess you're using implicit macro's there to instantiate Namer
    Oron Port
    I see no way around the runtime reflection here
    If you want class Bar to get the name of Bar
    To implement it should be something directly supported by the backend.
    Remy Willems
    I'll try an annotation macro @named. I have about a 1000 types inheriting from the reflection based Named so I'll be writing a bunch of annotations, but eh ^^
    Oron Port
    Yes, macro annotation that builds the tree is the best way.
    Kyle Daruwalla
    I have been struggling to enable macro paradise in an end-user build file. Here is the build.sbt:
    ThisBuild / autoCompilerPlugins := true
    ThisBuild / cancelable in Global := true
    ThisBuild / useSuperShell := false
    ThisBuild / organization := "com.github.uw-pharm"
    ThisBuild / scalaVersion := "2.12.6"
    addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full)
    lazy val iterative_svd = (project in file("IterativeSVD"))
        name := "iterative_svd",
        resolvers += Resolver.sonatypeRepo("releases"),
        scalacOptions += "-Xprint:macroparadise",
        scalacOptions += "-Xprint:superaccessors",
        scalacOptions += "-Xplugin:paradise_*.jar",
        libraryDependencies += "org.scalatest" %% "scalatest" % "3.0.5" % Test,
        libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value,
        libraryDependencies += "com.github.uw-pharm" % "bitsad-libraries_2.12" % "0.6.0-SNAPSHOT"
    I keep getting Enable macro paradise to expand macro annotations when I run iterative_svd/compile
    That’s the @compileTimeOnly error message I placed when I wrote the macro annotation
    I can’t figure out what I am missing
    Flavian Alexandru
    How do you enable macro annotations in Scala 2.13 builds? I have Compile / scalacOptions += "-Ymacro-annotations” set on specific sub projects where needed, but it seems to be ignored.