Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sbt doc fails on @typeclasses methods with scaladocs #90

Open
amirkarimi opened this issue Aug 22, 2017 · 3 comments
Open

sbt doc fails on @typeclasses methods with scaladocs #90

amirkarimi opened this issue Aug 22, 2017 · 3 comments

Comments

@amirkarimi
Copy link

amirkarimi commented Aug 22, 2017

Supposing the following implementation:

package example

import simulacrum.typeclass

/**
  * My formatter
  *
  * @tparam A
  */
@typeclass trait Show[A] {
  /**
    * Formats the model
    * @param a
    * @return
    */
  def show(a: A): String
}

object Shows {
  implicit val intShow = new Show[Int] {
    override def show(a: Int) = a.toString
  }
}

object Hello extends App {
  import Shows._
  import Show.ops._

  println(1.show)
}

Build.sbt:

lazy val root = (project in file(".")).
  settings(
    inThisBuild(List(
      organization := "com.example",
      scalaVersion := "2.12.2",
      version      := "0.1.0-SNAPSHOT"
    )),
    name := "Hello",
    addCompilerPlugin("org.scalamacros" % "paradise" % "2.1.0" cross CrossVersion.full),
    libraryDependencies ++= Seq(
      "com.github.mpilquist" %% "simulacrum" % "0.10.0"
    )
  )

It compiles successfully but running sbt doc will return the following error:

[error] .../simulacrum-doc-bug/src/main/scala/example/Hello.scala:29: value show is not a member of Int
[error]   println(1.show)
[error]             ^

It might have something to do with macro paradise.

@fosskers
Copy link

I was able to write a typeclass just now that has scaladocs on both the trait and its methods.

@dariuszpm
Copy link
Contributor

This issue still exists. If you write any scaladoc for any method in a trait annotated with @typeclass then sbt doc will fail. But only if you have any usage of your type class somewhere in code. Of course sbt compile works fine.

Happens only when using sbt doc:
Problem described by @amirkarimi is caused by the way how compiler is generating AST. During normal compilation methods are available as DefDef type even when they have scaladoc comment which is just ignored.
But during sbt doc compiler generates a little different AST. Every method that has scaladoc comment is described as DocDef(comment, DefDef(...)) which causes that macro isn't recognizing them at all and no methods (that has scaladoc comment) are added to generated trait Ops[_] for our type class.
That's why problem only occurs if there is any usage. Generated trait that you import doesn't have required method(s), ergo implicit conversion doesn't happen at all (this can be simply checked by adding compiler option: -Xlog-implicit-conversions), thus message about missing member.

Currently I have working solution to this problem, so I'll try to create a PR soon.

@mpilquist
Copy link
Member

mpilquist commented Jan 16, 2019 via email

mpilquist added a commit that referenced this issue Jan 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants