wix-incubator / accord

Accord: A sane validation library for Scala
http://wix.github.io/accord/
Other
529 stars 55 forks source link

ScalaDoc generation fails with pattern matches [WORKAROUND AVAILABLE] #119

Open tafli opened 7 years ago

tafli commented 7 years ago

We're using the newest version and tried pattern matching with guards as in the examples:

implicit val numericValidator = validator[ NumericPair ] { pair =>
pair.numeric match {
    case n if n < 0 => pair.string should startWith( "-" )
    case 0             => pair.string is equalTo( "0" )
    case n if n > 0 => pair.string is notEmpty
  }
}

Everything works fine with compiling and running but publishing fails as ScalaDoc seems to have a problem with the guards (without the guard its fine):

$ sbt doc
....
[info] This is a scaladoc compilation, Linter is disabled.
[error] <Accord>:1: not a legal formal parameter.
[error] Note: Tuples cannot be directly destructured in method or function parameters.
[error]       Either create a single parameter accepting the Tuple1,
[error]       or consider a pattern matching anonymous function: `{ case (param1, param1) => ... }
[error] n < 0 => 
[error]   ^
[error] <Accord>:1: illegal start of simple expression
[error] n < 0 => 
[error]         ^
[info] No documentation generated with unsuccessful compiler run
[error] two errors found
[error] (compile:doc) Scaladoc generation failed
....

Any ideas what the problem is?

Many thanks!

holograph commented 7 years ago

That is strange, I wonder what kind of weird magic goes on there. I'll look into it tomorrow and will let you know what I find.

holograph commented 7 years ago

Oh, and if you have a reproduction case you can share (ideally a repo I can clone or something similar), it'll save some time :-)

holograph commented 7 years ago

Well, I managed to reproduce this quite easily. I still have no idea what's going on here, but I'll see what I can do about it.

tafli commented 7 years ago

Great to hear you could reproduce it. Didn't manage to have a repo to reproduce.

holograph commented 7 years ago

Although I don't understand the issue properly yet, with some assistance from @eed3si9n there is at least a workaround: disabling macro expansions on the doc task. Add this to your build.sbt:

scalacOptions in (Compile, doc) += "-Ymacro-no-expand"

I've verified that this works on a sample repo: https://github.com/holograph/accord-issue119-sample

I'll keep this bug open for future investigation.

cwei-bgl commented 6 years ago

Hi, Is there an update on this?

With Scala version 2.12.4, it is not compiling even. I cannot do with the option -Ymacro-no-expand(-Ymacro-expand:none in new version), as I am using akka-http micro. Thanks.

holograph commented 6 years ago

I'm sorry to say that there hasn't, yet. I'm unclear on why the workaround doesn't work for you, though -- what does akka-http have to do with this?