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

Recompiling of file crashes when specialization annotation used and no package name defined #5023

Closed
scabug opened this issue Sep 23, 2011 · 5 comments
Assignees

Comments

@scabug
Copy link

scabug commented Sep 23, 2011

Compiler crashes when try to recompiling file with @specialized annotation, if there are no definition of package name.
With 'package somename' at the start of file recompiling works fine.

How to repeat:

$ cat test.scala
// no package definition available
object Main {
  def main(args: Array[String]) {
    val b = new A[Int](1)
  }
}
class A[@specialized(Int) T](val a: T)

$ rm *.class
$ scalac test.scala # success
$ scalac test.scala # failure
error: Companions 'class A$mcI$sp' and 'object A$mcI$sp' must be defined in same file
	at scala.tools.nsc.symtab.Symbols$Symbol.isCoDefinedWith(Symbols.scala:1268)
	at scala.tools.nsc.symtab.Symbols$Symbol$$anonfun$companionClass$1.apply(Symbols.scala:1304)
	at scala.tools.nsc.symtab.Symbols$Symbol$$anonfun$companionClass$1.apply(Symbols.scala:1304)
	at scala.tools.nsc.symtab.Symbols$Symbol.filter(Symbols.scala:1046)
	at scala.tools.nsc.symtab.Symbols$Symbol.suchThat(Symbols.scala:1051)
	at scala.tools.nsc.symtab.Symbols$Symbol.companionClass(Symbols.scala:1304)
	at scala.tools.nsc.symtab.Symbols$Symbol.companionSymbol(Symbols.scala:1334)
	at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:116)
	at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:85)
	at scala.tools.nsc.symtab.Symbols$Symbol.info(Symbols.scala:727)
	at scala.tools.nsc.symtab.Symbols$Symbol.initialize(Symbols.scala:839)
	at scala.tools.nsc.symtab.SymbolLoaders$moduleClassLoader$.doComplete(SymbolLoaders.scala:331)
	at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:111)
	at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:85)
	at scala.tools.nsc.symtab.Symbols$Symbol.info(Symbols.scala:727)
	at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$addInnerClasses$1$$anonfun$apply$mcV$sp$1.apply(GenJVM.scala:683)
	at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$addInnerClasses$1$$anonfun$apply$mcV$sp$1.apply(GenJVM.scala:683)
	at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
	at scala.collection.immutable.List.foreach(List.scala:45)
	at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$addInnerClasses$1.apply$mcV$sp(GenJVM.scala:683)
	at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$addInnerClasses$1.apply(GenJVM.scala:683)
	at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$addInnerClasses$1.apply(GenJVM.scala:683)
	at scala.tools.nsc.symtab.SymbolTable.atPhase(SymbolTable.scala:95)
	at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.addInnerClasses(GenJVM.scala:682)
	at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.emitClass(GenJVM.scala:171)
	at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genClass(GenJVM.scala:314)
	at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$run$4.apply(GenJVM.scala:86)
	at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$run$4.apply(GenJVM.scala:86)
	at scala.collection.mutable.HashMap$$anon$2$$anonfun$foreach$3.apply(HashMap.scala:102)
	at scala.collection.mutable.HashMap$$anon$2$$anonfun$foreach$3.apply(HashMap.scala:102)
	at scala.collection.Iterator$class.foreach(Iterator.scala:660)
	at scala.collection.mutable.HashTable$$anon$1.foreach(HashTable.scala:157)
	at scala.collection.mutable.HashTable$class.foreachEntry(HashTable.scala:190)
	at scala.collection.mutable.HashMap.foreachEntry(HashMap.scala:43)
	at scala.collection.mutable.HashMap$$anon$2.foreach(HashMap.scala:102)
	at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase.run(GenJVM.scala:86)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:953)
	at scala.tools.nsc.Global$Run.compile(Global.scala:1038)
	at scala.tools.nsc.Main$.process(Main.scala:106)
	at scala.tools.nsc.Main$.main(Main.scala:123)
	at scala.tools.nsc.Main.main(Main.scala)

Exception in thread "main" Companions 'class A$mcI$sp' and 'object A$mcI$sp' must be defined in same file
	at scala.tools.nsc.symtab.Symbols$Symbol.isCoDefinedWith(Symbols.scala:1268)
	at scala.tools.nsc.symtab.Symbols$Symbol$$anonfun$companionClass$1.apply(Symbols.scala:1304)
	at scala.tools.nsc.symtab.Symbols$Symbol$$anonfun$companionClass$1.apply(Symbols.scala:1304)
	at scala.tools.nsc.symtab.Symbols$Symbol.filter(Symbols.scala:1046)
	at scala.tools.nsc.symtab.Symbols$Symbol.suchThat(Symbols.scala:1051)
	at scala.tools.nsc.symtab.Symbols$Symbol.companionClass(Symbols.scala:1304)
	at scala.tools.nsc.symtab.Symbols$Symbol.companionSymbol(Symbols.scala:1334)
	at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:116)
	at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:85)
	at scala.tools.nsc.symtab.Symbols$Symbol.info(Symbols.scala:727)
	at scala.tools.nsc.symtab.Symbols$Symbol.initialize(Symbols.scala:839)
	at scala.tools.nsc.symtab.SymbolLoaders$moduleClassLoader$.doComplete(SymbolLoaders.scala:331)
	at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:111)
	at scala.tools.nsc.symtab.SymbolLoaders$SymbolLoader.complete(SymbolLoaders.scala:85)
	at scala.tools.nsc.symtab.Symbols$Symbol.info(Symbols.scala:727)
	at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$addInnerClasses$1$$anonfun$apply$mcV$sp$1.apply(GenJVM.scala:683)
	at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$addInnerClasses$1$$anonfun$apply$mcV$sp$1.apply(GenJVM.scala:683)
	at scala.collection.LinearSeqOptimized$class.foreach(LinearSeqOptimized.scala:59)
	at scala.collection.immutable.List.foreach(List.scala:45)
	at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$addInnerClasses$1.apply$mcV$sp(GenJVM.scala:683)
	at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$addInnerClasses$1.apply(GenJVM.scala:683)
	at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator$$anonfun$addInnerClasses$1.apply(GenJVM.scala:683)
	at scala.tools.nsc.symtab.SymbolTable.atPhase(SymbolTable.scala:95)
	at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.addInnerClasses(GenJVM.scala:682)
	at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.emitClass(GenJVM.scala:171)
	at scala.tools.nsc.backend.jvm.GenJVM$BytecodeGenerator.genClass(GenJVM.scala:314)
	at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$run$4.apply(GenJVM.scala:86)
	at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase$$anonfun$run$4.apply(GenJVM.scala:86)
	at scala.collection.mutable.HashMap$$anon$2$$anonfun$foreach$3.apply(HashMap.scala:102)
	at scala.collection.mutable.HashMap$$anon$2$$anonfun$foreach$3.apply(HashMap.scala:102)
	at scala.collection.Iterator$class.foreach(Iterator.scala:660)
	at scala.collection.mutable.HashTable$$anon$1.foreach(HashTable.scala:157)
	at scala.collection.mutable.HashTable$class.foreachEntry(HashTable.scala:190)
	at scala.collection.mutable.HashMap.foreachEntry(HashMap.scala:43)
	at scala.collection.mutable.HashMap$$anon$2.foreach(HashMap.scala:102)
	at scala.tools.nsc.backend.jvm.GenJVM$JvmPhase.run(GenJVM.scala:86)
	at scala.tools.nsc.Global$Run.compileSources(Global.scala:953)
	at scala.tools.nsc.Global$Run.compile(Global.scala:1038)
	at scala.tools.nsc.Main$.process(Main.scala:106)
	at scala.tools.nsc.Main$.main(Main.scala:123)
	at scala.tools.nsc.Main.main(Main.scala)
@scabug
Copy link
Author

scabug commented Sep 23, 2011

Imported From: https://issues.scala-lang.org/browse/SI-5023?orig=1
Reporter: andy legkiy (easy)
Affected Versions: 2.9.1

@scabug
Copy link
Author

scabug commented Oct 14, 2011

@retronym said:
Regression from 2.9.0

@scabug
Copy link
Author

scabug commented Oct 15, 2011

Commit Message Bot (anonymous) said:
(extempore in r25831) Fix regression in companion check.

Pulling back from expensive path normalization caused a regression
where companions were no longer recognized as such after specialization.
(Specifically, the paths turned up as "test.scala" and "./test.scala".)
I made it a two-level check, doing the expensive one before failing.
Closes #5023, no review.

@scabug scabug closed this as completed Oct 15, 2011
@scabug
Copy link
Author

scabug commented Oct 16, 2011

Ben Wing (benwing) said:
Hi. I don't know the Scala compiler but my sense is that this is the wrong approach. Comparing two paths is a common operation and hence you may get bit by this bug repeatedly unless you add a comparePaths() function which implements the above procedure, i.e. compare the un-normalized paths, then normalize paths and recompare.

@scabug
Copy link
Author

scabug commented Oct 16, 2011

@paulp said:
If you can point me to a second place in the compiler where correctness depends on the result of comparing paths for equality, I will be happy to generalize it.

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