diff options
author | Paul Phillips <paulp@improving.org> | 2011-10-15 00:14:04 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-10-15 00:14:04 +0000 |
commit | e52053f10b65105ca6ba58806da41a0d14803a37 (patch) | |
tree | 644632ac8a1f7c7e2a34f15286b6c859ea964847 | |
parent | 9ea2cefb2079aebad2b215f6a699fe6262e2c7a7 (diff) | |
download | scala-e52053f10b65105ca6ba58806da41a0d14803a37.tar.gz scala-e52053f10b65105ca6ba58806da41a0d14803a37.tar.bz2 scala-e52053f10b65105ca6ba58806da41a0d14803a37.zip |
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 SI-5023, no review.
-rw-r--r-- | src/compiler/scala/reflect/internal/Required.scala | 5 | ||||
-rw-r--r-- | src/compiler/scala/reflect/internal/Symbols.scala | 14 | ||||
-rw-r--r-- | src/compiler/scala/reflect/runtime/AbstractFile.scala | 1 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/io/AbstractFile.scala | 3 | ||||
-rw-r--r-- | test/files/neg/t1286.check | 6 |
5 files changed, 22 insertions, 7 deletions
diff --git a/src/compiler/scala/reflect/internal/Required.scala b/src/compiler/scala/reflect/internal/Required.scala index 874eb2f9ae..1bf1a2e97e 100644 --- a/src/compiler/scala/reflect/internal/Required.scala +++ b/src/compiler/scala/reflect/internal/Required.scala @@ -5,7 +5,10 @@ import settings.MutableSettings trait Required { self: SymbolTable => - type AbstractFileType >: Null <: { def path: String } + type AbstractFileType >: Null <: { + def path: String + def canonicalPath: String + } def picklerPhase: Phase diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala index 4ded91c16c..cd60b85ff5 100644 --- a/src/compiler/scala/reflect/internal/Symbols.scala +++ b/src/compiler/scala/reflect/internal/Symbols.scala @@ -1446,8 +1446,12 @@ trait Symbols extends api.Symbols { self: SymbolTable => (this.sourceFile == that.sourceFile) || { // recognize companion object in separate file and fail, else compilation // appears to succeed but highly opaque errors come later: see bug #1286 - if (this.sourceFile.path != that.sourceFile.path) - throw InvalidCompanions(this, that) + if (this.sourceFile.path != that.sourceFile.path) { + // The cheaper check can be wrong: do the expensive normalization + // before failing. + if (this.sourceFile.canonicalPath != that.sourceFile.canonicalPath) + throw InvalidCompanions(this, that) + } false } @@ -2404,8 +2408,10 @@ trait Symbols extends api.Symbols { self: SymbolTable => // printStackTrace() // debug } - case class InvalidCompanions(sym1: Symbol, sym2: Symbol) - extends Throwable("Companions '" + sym1 + "' and '" + sym2 + "' must be defined in same file") { + case class InvalidCompanions(sym1: Symbol, sym2: Symbol) extends Throwable( + "Companions '" + sym1 + "' and '" + sym2 + "' must be defined in same file:\n" + + " Found in " + sym1.sourceFile.canonicalPath + " and " + sym2.sourceFile.canonicalPath + ) { override def toString = getMessage } diff --git a/src/compiler/scala/reflect/runtime/AbstractFile.scala b/src/compiler/scala/reflect/runtime/AbstractFile.scala index 04f18bcd3b..bf3b47298b 100644 --- a/src/compiler/scala/reflect/runtime/AbstractFile.scala +++ b/src/compiler/scala/reflect/runtime/AbstractFile.scala @@ -2,4 +2,5 @@ package scala.reflect.runtime class AbstractFile(val jfile: java.io.File) { def path: String = jfile.getPath() + def canonicalPath: String = jfile.getCanonicalPath() }
\ No newline at end of file diff --git a/src/compiler/scala/tools/nsc/io/AbstractFile.scala b/src/compiler/scala/tools/nsc/io/AbstractFile.scala index d60ecd8734..27dd8625a5 100644 --- a/src/compiler/scala/tools/nsc/io/AbstractFile.scala +++ b/src/compiler/scala/tools/nsc/io/AbstractFile.scala @@ -89,6 +89,9 @@ abstract class AbstractFile extends AnyRef with Iterable[AbstractFile] { /** Returns the path of this abstract file. */ def path: String + /** Returns the path of this abstract file in a canonical form. */ + def canonicalPath: String = if (file == null) path else file.getCanonicalPath + /** Checks extension case insensitively. */ def hasExtension(other: String) = extension == other.toLowerCase private lazy val extension: String = Path.extension(name) diff --git a/test/files/neg/t1286.check b/test/files/neg/t1286.check index 734964e9cf..2699f0789d 100644 --- a/test/files/neg/t1286.check +++ b/test/files/neg/t1286.check @@ -1,7 +1,9 @@ -a.scala:1: error: Companions 'object Foo' and 'trait Foo' must be defined in same file +a.scala:1: error: Companions 'object Foo' and 'trait Foo' must be defined in same file: + Found in files/neg/t1286/b.scala and files/neg/t1286/a.scala trait Foo { ^ -b.scala:1: error: Companions 'trait Foo' and 'object Foo' must be defined in same file +b.scala:1: error: Companions 'trait Foo' and 'object Foo' must be defined in same file: + Found in files/neg/t1286/a.scala and files/neg/t1286/b.scala object Foo extends Foo { ^ two errors found |