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-scoverage plugin causes compilation error #60

Closed
noamBarkai opened this issue Feb 11, 2016 · 6 comments
Closed

sbt-scoverage plugin causes compilation error #60

noamBarkai opened this issue Feb 11, 2016 · 6 comments
Assignees

Comments

@noamBarkai
Copy link

to reproduce, add to project/plugins.sbt

resolvers += Resolver.url("scoverage-bintray", url("https://dl.bintray.com/sksamuel/sbt-plugins/"))(Resolver.ivyStylePatterns)

addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.3.5")

and to build.sbt:

name := "reproduce-accord-bug"

version := "1.0"

scalaVersion := "2.10.5"

libraryDependencies += "com.wix" % "accord-core_2.10" % "0.5"

next create the following Scala class:

import com.wix.accord.dsl
import dsl._    // Import the validator DSL

case class Person( firstName: String, lastName: String )
case class Classroom( teacher: Person, students: Seq[ Person ] )

class School {
  implicit val personValidator = validator[ Person ] { p =>
    p.firstName is notEmpty                   // The expression being validated is resolved automatically, see below
    p.lastName as "last name" is notEmpty     // You can also explicitly describe the expression being validated
  }

  implicit val classValidator = validator[ Classroom ] { c =>
    c.teacher is valid        // Implicitly relies on personValidator!
    c.students.each is valid
    c.students have size > 0
  }
}

finally running from sbt:
sbt coverage compile

you should see the following error:
[error] while compiling: /home/noamb/reproduce-accord-bug/src/main/scala-2.10/ReproduceBug.scala
[error] during phase: typer
[error] library version: version 2.10.5
[error] compiler version: version 2.10.5
...
[error] last tree to typer: Ident(Classroom)
[error] symbol: object Classroom (flags: )
[error] symbol definition: object Classroom
[error] tpe: Classroom.type
[error] symbol owners: object Classroom -> package
[error] context owners: method readResolve -> object Classroom -> package
[error]
[error] == Enclosing template or block ==
[error]
[error] DefDef( // private def readResolve(): Object in object Classroom
[error] private
[error] "readResolve"
[error] []
[error] List(Nil)
[error] // tree.tpe=Object
[error] "Classroom" // object Classroom, tree.tpe=Classroom.type
[error] )
[error]
[error] == Expanded type of tree ==
[error]
[error] TypeRef(
[error] TypeSymbol(
[error] class Classroom extends AbstractFunction2[Person,Seq[Person],Classroom] with Serializable
[error]
[error] )
[error] )
[error]
[error] uncaught exception during compilation: scala.tools.nsc.interactive.RangePositions$ValidateException
scala.tools.nsc.interactive.RangePositions$ValidateException: Synthetic tree [2958] contains nonsynthetic tree [2792]


Scala version 2.10.5
SBT version 0.13.8
Accord version 0.5
sbt-scoverage version 1.3.5
@holograph
Copy link
Contributor

Reproduced locally. Trying to work it out...

@holograph
Copy link
Contributor

Interim results:

  • Only happens with Scala 2.10 (works fine with 2.11);
  • The coverage task changes the active Scala version for some reason, I verified instead with coverageEnabled := true

I don't suppose as a temporary workaround you can switch to 2.11? :-)

@holograph
Copy link
Contributor

Sample output:

> last compile:compileIncremental
[debug]
[debug] Initial source changes:
[debug]     removed:Set()
[debug]     added: Set(/Users/tomerga/dev/bugrepro/src/main/scala/School.scala)
[debug]     modified: Set()
[debug] Invalidated products: Set()
[debug] External API changes: API Changes: Set()
[debug] Modified binary dependencies: Set()
[debug] Initial directly invalidated sources: Set(/Users/tomerga/dev/bugrepro/src/main/scala/School.scala)
[debug]
[debug] Sources indirectly invalidated by:
[debug]     product: Set()
[debug]     binary dep: Set()
[debug]     external source: Set()
[debug] All initially invalidated sources: Set(/Users/tomerga/dev/bugrepro/src/main/scala/School.scala)
[debug] Recompiling all 1 sources: invalidated sources (1) exceeded 50.0% of all sources
[info] Compiling 1 Scala source to /Users/tomerga/dev/bugrepro/target/scala-2.10/classes...
[debug] Getting compiler-interface from component compiler for Scala 2.10.5
[debug] Getting compiler-interface from component compiler for Scala 2.10.5
[debug] Running cached compiler 3c1480a2, interfacing (CompilerInterface) with Scala compiler version 2.10.5
[debug] Calling Scala compiler with arguments  (CompilerInterface):
[debug]     -Xplugin:/Users/tomerga/.ivy2/cache/org.scoverage/scalac-scoverage-plugin_2.10/jars/scalac-scoverage-plugin_2.10-1.1.1.jar
[debug]     -P:scoverage:dataDir:/Users/tomerga/dev/bugrepro/target/scala-2.10/scoverage-data
[debug]     -Yrangepos
[debug]     -bootclasspath
[debug]     /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/classes:/Users/tomerga/.sbt/boot/scala-2.10.5/lib/scala-library.jar
[debug]     -classpath
[debug]     /Users/tomerga/dev/bugrepro/target/scala-2.10/classes:/Users/tomerga/.ivy2/cache/com.wix/accord-core_2.10/jars/accord-core_2.10-0.5.jar:/Users/tomerga/.ivy2/cache/com.wix/accord-api_2.10/jars/accord-api_2.10-0.5.jar:/Users/tomerga/.ivy2/cache/org.scalamacros/quasiquotes_2.10/jars/quasiquotes_2.10-2.0.1.jar:/Users/tomerga/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.10.4.jar:/Users/tomerga/.ivy2/cache/org.scoverage/scalac-scoverage-runtime_2.10/jars/scalac-scoverage-runtime_2.10-1.1.1.jar:/Users/tomerga/.ivy2/cache/org.scoverage/scalac-scoverage-plugin_2.10/jars/scalac-scoverage-plugin_2.10-1.1.1.jar
[info] ======= Position error
[info] Synthetic tree [2960] contains nonsynthetic tree [2794]
[info] == Enclosing tree [2960] of type DefDef at [262]School.scala
[info]
[info] [L   8        ] #2960   [262]           DefDef     // term apply
[info]
[info] == Enclosed tree [2794] of type ValDef at [264:265]School.scala
[info]
[info] [L   8        ] #2794   [264:265]       ValDef     // p
[info]
[info]
[info] While validating #5294
[info] [L   1        ] #5294   [0:700]         PackageDef // import com.wix.accord.dsl
[info]
[info] Children:
[info]   [L   1 P# 5294] #172    [0:0]           Ident      // i
[info]   [L   1 P# 5294] #44     [0:25]          Import     // com.wix.accord.dsl
[info]   [L   2 P# 5294] #341    [26:38]         Import     // dsl._    // I
[info]   [L   4 P# 5294] #623    [71:127]        ClassDef   // Person( firstName: String, lastName: String )
[info]   [L   4 P# 5294] #5166   [82]            ModuleDef  // term Person
[info]   [L   5 P# 5294] #897    [128:192]       ClassDef   // Classroom( teacher: Person, students: Seq[ Person ] )
[info]   [L   5 P# 5294] #5293   [139]           ModuleDef  // term Classroom
[info]   [L   7 P# 5294] #4999   [194:700]       ClassDef   // School {
[info] =======
[error]
[error]      while compiling: /Users/tomerga/dev/bugrepro/src/main/scala/School.scala
[error]         during phase: typer
[error]      library version: version 2.10.5
[error]     compiler version: version 2.10.5
[error]   reconstructed args: -Xplugin:/Users/tomerga/.ivy2/cache/org.scoverage/scalac-scoverage-plugin_2.10/jars/scalac-scoverage-plugin_2.10-1.1.1.jar -Yrangepos -P:scoverage:dataDir:/Users/tomerga/dev/bugrepro/target/scala-2.10/scoverage-data -bootclasspath /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/sunrsasign.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/classes:/Users/tomerga/.sbt/boot/scala-2.10.5/lib/scala-library.jar -classpath /Users/tomerga/dev/bugrepro/target/scala-2.10/classes:/Users/tomerga/.ivy2/cache/com.wix/accord-core_2.10/jars/accord-core_2.10-0.5.jar:/Users/tomerga/.ivy2/cache/com.wix/accord-api_2.10/jars/accord-api_2.10-0.5.jar:/Users/tomerga/.ivy2/cache/org.scalamacros/quasiquotes_2.10/jars/quasiquotes_2.10-2.0.1.jar:/Users/tomerga/.ivy2/cache/org.scala-lang/scala-reflect/jars/scala-reflect-2.10.4.jar:/Users/tomerga/.ivy2/cache/org.scoverage/scalac-scoverage-runtime_2.10/jars/scalac-scoverage-runtime_2.10-1.1.1.jar:/Users/tomerga/.ivy2/cache/org.scoverage/scalac-scoverage-plugin_2.10/jars/scalac-scoverage-plugin_2.10-1.1.1.jar
[error]
[error]   last tree to typer: Ident(Classroom)
[error]               symbol: object Classroom (flags: <module> <synthetic>)
[error]    symbol definition: object Classroom
[error]                  tpe: Classroom.type
[error]        symbol owners: object Classroom -> package <empty>
[error]       context owners: method readResolve -> object Classroom -> package <empty>
[error]
[error] == Enclosing template or block ==
[error]
[error] DefDef( // private def readResolve(): Object in object Classroom
[error]   <method> private <synthetic>
[error]   "readResolve"
[error]   []
[error]   List(Nil)
[error]   <tpt> // tree.tpe=Object
[error]   "Classroom" // object Classroom, tree.tpe=Classroom.type
[error] )
[error]
[error] == Expanded type of tree ==
[error]
[error] TypeRef(
[error]   TypeSymbol(
[error]     class Classroom extends AbstractFunction2[Person,Seq[Person],Classroom] with Serializable
[error]
[error]   )
[error] )
[error]
[error] uncaught exception during compilation: scala.tools.nsc.interactive.RangePositions$ValidateException
scala.tools.nsc.interactive.RangePositions$ValidateException: Synthetic tree [2960] contains nonsynthetic tree [2794]
    at scala.tools.nsc.interactive.RangePositions$class.positionError$1(RangePositions.scala:201)
    at scala.tools.nsc.interactive.RangePositions$class.validate$1(RangePositions.scala:218)
    at scala.tools.nsc.interactive.RangePositions$class.validate$1(RangePositions.scala:241)
    at scala.tools.nsc.interactive.RangePositions$class.validate$1(RangePositions.scala:241)
    at scala.tools.nsc.interactive.RangePositions$class.validate$1(RangePositions.scala:241)
    at scala.tools.nsc.interactive.RangePositions$class.validate$1(RangePositions.scala:241)
    at scala.tools.nsc.interactive.RangePositions$class.validate$1(RangePositions.scala:241)
    at scala.tools.nsc.interactive.RangePositions$class.validate$1(RangePositions.scala:241)
    at scala.tools.nsc.interactive.RangePositions$class.validate$1(RangePositions.scala:241)
    at scala.tools.nsc.interactive.RangePositions$class.validate$1(RangePositions.scala:241)
    at scala.tools.nsc.interactive.RangePositions$class.validate$1(RangePositions.scala:241)
    at scala.tools.nsc.interactive.RangePositions$class.validatePositions(RangePositions.scala:246)
    at xsbt.CachedCompiler0$$anon$1.validatePositions(CompilerInterface.scala:150)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.apply(Analyzer.scala:100)
    at scala.tools.nsc.Global$GlobalPhase.applyPhase(Global.scala:464)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:91)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3$$anonfun$run$1.apply(Analyzer.scala:91)
    at scala.collection.Iterator$class.foreach(Iterator.scala:727)
    at scala.collection.AbstractIterator.foreach(Iterator.scala:1157)
    at scala.tools.nsc.typechecker.Analyzer$typerFactory$$anon$3.run(Analyzer.scala:91)
    at scala.tools.nsc.Global$Run.compileUnitsInternal(Global.scala:1583)
    at scala.tools.nsc.Global$Run.compileUnits(Global.scala:1557)
    at scala.tools.nsc.Global$Run.compileSources(Global.scala:1553)
    at scala.tools.nsc.Global$Run.compile(Global.scala:1662)
    at xsbt.CachedCompiler0.run(CompilerInterface.scala:116)
    at xsbt.CachedCompiler0.run(CompilerInterface.scala:95)
    at xsbt.CompilerInterface.run(CompilerInterface.scala:26)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:497)
    at sbt.compiler.AnalyzingCompiler.call(AnalyzingCompiler.scala:101)
    at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:47)
    at sbt.compiler.AnalyzingCompiler.compile(AnalyzingCompiler.scala:41)
    at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply$mcV$sp(MixedAnalyzingCompiler.scala:51)
    at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply(MixedAnalyzingCompiler.scala:51)
    at sbt.compiler.MixedAnalyzingCompiler$$anonfun$compileScala$1$1.apply(MixedAnalyzingCompiler.scala:51)
    at sbt.compiler.MixedAnalyzingCompiler.timed(MixedAnalyzingCompiler.scala:75)
    at sbt.compiler.MixedAnalyzingCompiler.compileScala$1(MixedAnalyzingCompiler.scala:50)
    at sbt.compiler.MixedAnalyzingCompiler.compile(MixedAnalyzingCompiler.scala:65)
    at sbt.compiler.IC$$anonfun$compileInternal$1.apply(IncrementalCompiler.scala:160)
    at sbt.compiler.IC$$anonfun$compileInternal$1.apply(IncrementalCompiler.scala:160)
    at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:66)
    at sbt.inc.IncrementalCompile$$anonfun$doCompile$1.apply(Compile.scala:64)
    at sbt.inc.IncrementalCommon.cycle(IncrementalCommon.scala:31)
    at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:62)
    at sbt.inc.Incremental$$anonfun$1.apply(Incremental.scala:61)
    at sbt.inc.Incremental$.manageClassfiles(Incremental.scala:89)
    at sbt.inc.Incremental$.compile(Incremental.scala:61)
    at sbt.inc.IncrementalCompile$.apply(Compile.scala:54)
    at sbt.compiler.IC$.compileInternal(IncrementalCompiler.scala:160)
    at sbt.compiler.IC$.incrementalCompile(IncrementalCompiler.scala:138)
    at sbt.Compiler$.compile(Compiler.scala:128)
    at sbt.Compiler$.compile(Compiler.scala:114)
    at sbt.Defaults$.sbt$Defaults$$compileIncrementalTaskImpl(Defaults.scala:829)
    at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:820)
    at sbt.Defaults$$anonfun$compileIncrementalTask$1.apply(Defaults.scala:818)
    at scala.Function1$$anonfun$compose$1.apply(Function1.scala:47)
    at sbt.$tilde$greater$$anonfun$$u2219$1.apply(TypeFunctions.scala:40)
    at sbt.std.Transform$$anon$4.work(System.scala:63)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1$$anonfun$apply$1.apply(Execute.scala:226)
    at sbt.ErrorHandling$.wideConvert(ErrorHandling.scala:17)
    at sbt.Execute.work(Execute.scala:235)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.Execute$$anonfun$submit$1.apply(Execute.scala:226)
    at sbt.ConcurrentRestrictions$$anon$4$$anonfun$1.apply(ConcurrentRestrictions.scala:159)
    at sbt.CompletionService$$anon$2.call(CompletionService.scala:28)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
[error] (compile:compileIncremental) scala.tools.nsc.interactive.RangePositions$ValidateException: Synthetic tree [2960] contains nonsynthetic tree [2794]

@noamBarkai
Copy link
Author

yah, Scala 2.11 would be more of a work-detour than a work-around :-)

@holograph
Copy link
Contributor

This is evidently not an scoverage-specific thing, but rather that scoverage configures scalac with -Yrangepos. This is entirely reproducible with removing scoverage and adding scalacOptions += "-Yrangepos" to your build. (via StackOverflow)

@holograph
Copy link
Contributor

This is, unfortunately, a known bug in Scala 2.10 (see SI-8510). Seeing as 2.10 is pretty much end-of-lifed, I don't expect it to ever be fixed, and is a non-issue for 2.11 up.

Unfortunately I haven't been able to dig up a workaround, and since this not an Accord-specific issue (you're liable to run into this problem with any macro library, including most JSON libraries, shapeless, specs2 etc.) I don't think I can justify the time digging further into this. I'd be happy to help if anyone else is interested, though :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants