From 1065c911a1b896132b54d2573d80152b5fe7404f Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Mon, 7 Feb 2011 04:45:44 +0000 Subject: The comment for isCoDefinedWith has long said Is this symbol defined in the same scope and compilation unit as `that' symbol? But "same scope" was never checked, only "same compilation unit." Presumably other layers of logic kept this from being noticed until now, but it has been crashing sbt. Added check to isCoDefinedWith. Closes #4220, review by odersky. --- src/compiler/scala/tools/nsc/symtab/Symbols.scala | 27 +++++++++++++---------- test/files/pos/bug4220.scala | 7 ++++++ 2 files changed, 22 insertions(+), 12 deletions(-) create mode 100644 test/files/pos/bug4220.scala diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala index 6a15c929b9..7aa15d2e42 100644 --- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala +++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala @@ -1224,19 +1224,22 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable => /** Is this symbol defined in the same scope and compilation unit as `that' symbol? */ - def isCoDefinedWith(that: Symbol) = (this.rawInfo ne NoType) && { - !this.owner.isPackageClass || - (this.sourceFile eq null) || - (that.sourceFile eq null) || - (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) - - false + def isCoDefinedWith(that: Symbol) = ( + (this.rawInfo ne NoType) && + (this.owner == that.owner) && { + !this.owner.isPackageClass || + (this.sourceFile eq null) || + (that.sourceFile eq null) || + (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) + + false + } } - } + ) /** The internal representation of classes and objects: * diff --git a/test/files/pos/bug4220.scala b/test/files/pos/bug4220.scala new file mode 100644 index 0000000000..98f2649767 --- /dev/null +++ b/test/files/pos/bug4220.scala @@ -0,0 +1,7 @@ +// don't know if our half-working sbt build is meaningfully +// tested for #4220 with this, but it can't hurt. +class Boo(a: Int = 0) + +object test { + class Boo +} -- cgit v1.2.3