zinc icon indicating copy to clipboard operation
zinc copied to clipboard

Failed to find name hashed for types with `$$`

Open yufangong opened this issue 7 years ago • 9 comments

It works fine with sbt version 1.0.2, but start failing 1.0.3 and greater. I found this commit might be related.

Error message:

[error] java.lang.RuntimeException: Failed to find name hashes for com.twitter.scrooge.serializer.thriftscala.SerializerListTest$$Adapt
[error]     at scala.sys.package$.error(package.scala:27)
[error]     at sbt.internal.inc.AnalysisCallback.nameHashesForCompanions(Compile.scala:325)
[error]     at sbt.internal.inc.AnalysisCallback.analyzeClass(Compile.scala:332)
[error]     at sbt.internal.inc.AnalysisCallback.$anonfun$addProductsAndDeps$4(Compile.scala:348)
[error]     at scala.collection.TraversableLike.$anonfun$map$1(TraversableLike.scala:234)
[error]     at scala.collection.mutable.HashSet.foreach(HashSet.scala:78)
[error]     at scala.collection.TraversableLike.map(TraversableLike.scala:234)
[error]     at scala.collection.TraversableLike.map$(TraversableLike.scala:227)
[error]     at scala.collection.mutable.AbstractSet.scala$collection$SetLike$$super$map(Set.scala:46)
[error]     at scala.collection.SetLike.map(SetLike.scala:101)
[error]     at scala.collection.SetLike.map$(SetLike.scala:101)
[error]     at scala.collection.mutable.AbstractSet.map(Set.scala:46)
[error]     at sbt.internal.inc.AnalysisCallback.$anonfun$addProductsAndDeps$1(Compile.scala:348)
[error]     at scala.collection.TraversableOnce.$anonfun$foldLeft$1(TraversableOnce.scala:157)
[error]     at scala.collection.TraversableOnce.$anonfun$foldLeft$1$adapted(TraversableOnce.scala:157)
[error]     at scala.collection.mutable.HashSet.foreach(HashSet.scala:78)
[error]     at scala.collection.TraversableOnce.foldLeft(TraversableOnce.scala:157)
[error]     at scala.collection.TraversableOnce.foldLeft$(TraversableOnce.scala:155)
[error]     at scala.collection.AbstractTraversable.foldLeft(Traversable.scala:104)
[error]     at scala.collection.TraversableOnce.$div$colon(TraversableOnce.scala:151)
[error]     at scala.collection.TraversableOnce.$div$colon$(TraversableOnce.scala:151)
[error]     at scala.collection.AbstractTraversable.$div$colon(Traversable.scala:104)
[error]     at sbt.internal.inc.AnalysisCallback.addProductsAndDeps(Compile.scala:344)
[error]     at sbt.internal.inc.AnalysisCallback.get(Compile.scala:294)
[error]     at sbt.internal.inc.Incremental$.doCompile(Incremental.scala:102)
[error]     at sbt.internal.inc.Incremental$.$anonfun$compile$4(Incremental.scala:82)
[error]     at sbt.internal.inc.IncrementalCommon.recompileClasses(IncrementalCommon.scala:117)
[error]     at sbt.internal.inc.IncrementalCommon.cycle(IncrementalCommon.scala:64)
[error]     at sbt.internal.inc.Incremental$.$anonfun$compile$3(Incremental.scala:84)
[error]     at sbt.internal.inc.Incremental$.manageClassfiles(Incremental.scala:129)
[error]     at sbt.internal.inc.Incremental$.compile(Incremental.scala:75)
[error]     at sbt.internal.inc.IncrementalCompile$.apply(Compile.scala:70)
[error]     at sbt.internal.inc.IncrementalCompilerImpl.compileInternal(IncrementalCompilerImpl.scala:309)
[error]     at sbt.internal.inc.IncrementalCompilerImpl.$anonfun$compileIncrementally$1(IncrementalCompilerImpl.scala:267)
[error]     at sbt.internal.inc.IncrementalCompilerImpl.handleCompilationError(IncrementalCompilerImpl.scala:158)
[error]     at sbt.internal.inc.IncrementalCompilerImpl.compileIncrementally(IncrementalCompilerImpl.scala:237)
[error]     at sbt.internal.inc.IncrementalCompilerImpl.compile(IncrementalCompilerImpl.scala:68)
[error]     at sbt.Defaults$.compileIncrementalTaskImpl(Defaults.scala:1403)
[error]     at sbt.Defaults$.$anonfun$compileIncrementalTask$1(Defaults.scala:1385)
[error]     at scala.Function1.$anonfun$compose$1(Function1.scala:44)
[error]     at sbt.internal.util.$tilde$greater.$anonfun$$u2219$1(TypeFunctions.scala:42)
[error]     at sbt.std.Transform$$anon$4.work(System.scala:64)
[error]     at sbt.Execute.$anonfun$submit$2(Execute.scala:257)
[error]     at sbt.internal.util.ErrorHandling$.wideConvert(ErrorHandling.scala:16)
[error]     at sbt.Execute.work(Execute.scala:266)
[error]     at sbt.Execute.$anonfun$submit$1(Execute.scala:257)
[error]     at sbt.ConcurrentRestrictions$$anon$4.$anonfun$submitValid$1(ConcurrentRestrictions.scala:167)
[error]     at sbt.CompletionService$$anon$2.call(CompletionService.scala:32)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]     at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
[error]     at java.util.concurrent.FutureTask.run(FutureTask.java:266)
[error]     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
[error]     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
[error]     at java.lang.Thread.run(Thread.java:745)
[error] (scrooge-serializer/test:compileIncremental) Failed to find name hashes for com.twitter.scrooge.serializer.thriftscala.SerializerListTest$$Adapt
[error] Total time: 6 s, completed Apr 19, 2018 2:44:17 PM

yufangong avatar Apr 19 '18 22:04 yufangong

could you provide a minimised reproduction (code+steps) for this, please?

dwijnand avatar Apr 23 '18 06:04 dwijnand

And also make sure you're not using cached analysis files generated by previous Zinc versions.

jvican avatar Apr 23 '18 08:04 jvican

Thank you @dwijnand and @jvican, and sorry I cannot minimize the code for reproduction, but I'll try to elaborate the problem.

We have this code generator called Scrooge, in some situation, it generates Java class files under target/scala-2.12/test-classes/, such as this SerializerListTest$$Adapt.class. Sbt works fine with this until version 1.0.3, throwing the exception as above.

Reproduce:

  1. $ git clone scrooge repo
  2. change the build.properties to sbt 1.0.3 or greater
  3. $ sbt 'project scrooge-serializer' 'test'

yufangong avatar Apr 24 '18 21:04 yufangong

@yufangong Thanks for that. Could you also please minimize the problematic SerializerListTest example so that we can add it to our test suite and fix this issue? Also, is scrooge by any chance adding those $$ in the generated class name or is that done by Scala? It would be valuable if you show us what Scala code scrooge generates for SerializerListTest.

jvican avatar May 03 '18 12:05 jvican

Now that pants has upgraded to 1.1.7, we're seeing this as well. Can repro by compiling:

$ cat Odd.scala
object Odd$$Example {
  def main(args: Array[String]) {
    println(s"Well, that's odd: ${args.toSeq}")
  }
}

stuhood avatar Jun 24 '18 17:06 stuhood

I'll take a look at fixing this today.

stuhood avatar Jun 24 '18 17:06 stuhood

It looks like this one might go fairly deep into a rabbit hole. It's very, very easy to reproduce in a zinc test: I've pushed a repro here: https://github.com/sbt/zinc/compare/1.x...stuhood:stuhood/double-dollar .

Take this investigation with a grain of salt, but:

The issue appears to be that nothing ever calls void api(File sourceFile, xsbti.api.ClassLike classApi); for the class. From what I can tell, what should be calling that method in this case is the analysis callback in the compiler bridge.

As far as I can tell, the TopLevelTraverser in scala.xsbt.API never observes the class in the Tree, and so never calls ExtractAPI.extractAllClassesOf for it.

I'm going to give up on this one for now, because (if I understand this correctly), that means that either the class is not in the Tree (...which seems unlikely) or we're not traversing the Tree correctly... and someone with more knowledge of the compiler would be able to move more quickly in there. cc @retronym , @jvican

stuhood avatar Jun 24 '18 19:06 stuhood

...but @yufangong 's linked PR definitely looks relevant.

stuhood avatar Jun 24 '18 20:06 stuhood

I was able to work around this by using a different namespacing character in this generated code, so I think we're unblocked.

stuhood avatar Jun 24 '18 22:06 stuhood