diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/symtab/Symbols.scala | 9 | ||||
-rw-r--r-- | test/files/neg/bug1286.check | 2 | ||||
-rw-r--r-- | test/files/neg/bug1286/a.scala | 3 | ||||
-rw-r--r-- | test/files/neg/bug1286/b.scala | 3 |
4 files changed, 17 insertions, 0 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 106b737672..6cae7d5835 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -1045,6 +1045,15 @@ trait Symbols { (that.sourceFile eq null) || (this.sourceFile eq that.sourceFile) || (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 (res == false) { + val (f1, f2) = (this.sourceFile, that.sourceFile) + if (f1 != null && f2 != null && f1 != f2) + throw FatalError("Companions '" + this + "' and '" + that + "' must be defined in same file.") + } + res } diff --git a/test/files/neg/bug1286.check b/test/files/neg/bug1286.check new file mode 100644 index 0000000000..9bf63252cc --- /dev/null +++ b/test/files/neg/bug1286.check @@ -0,0 +1,2 @@ +error: fatal error: Companions 'object Foo' and 'trait Foo' must be defined in same file. +one error found diff --git a/test/files/neg/bug1286/a.scala b/test/files/neg/bug1286/a.scala new file mode 100644 index 0000000000..0300ce793c --- /dev/null +++ b/test/files/neg/bug1286/a.scala @@ -0,0 +1,3 @@ +trait Foo { + def jump = Foo.x +}
\ No newline at end of file diff --git a/test/files/neg/bug1286/b.scala b/test/files/neg/bug1286/b.scala new file mode 100644 index 0000000000..0df474461e --- /dev/null +++ b/test/files/neg/bug1286/b.scala @@ -0,0 +1,3 @@ +object Foo extends Foo { + val x = "x" +}
\ No newline at end of file |