summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLukas Rytz <lukas.rytz@gmail.com>2016-10-26 16:43:36 +0200
committerLukas Rytz <lukas.rytz@gmail.com>2016-10-26 20:54:55 +0200
commitbd1858896f6546d778aa93c39b491ed5e2d7e0b3 (patch)
tree2d14a1933d38e253a38c18304c1d4c252a5cbd8f
parenteff0aabb7824513498a4081072845001dbe4897f (diff)
downloadscala-bd1858896f6546d778aa93c39b491ed5e2d7e0b3.tar.gz
scala-bd1858896f6546d778aa93c39b491ed5e2d7e0b3.tar.bz2
scala-bd1858896f6546d778aa93c39b491ed5e2d7e0b3.zip
Ensure companionClass returns a class, not a type alias
This fixes scala/scala-dev#248, where a type alias reached the backend through this method. This is very similar to the fix for SI-5031, which changed it only in ModuleSymbol, but not in Symbol. The override in ModuleSymbol is actually unnecessary (it's identical), so it's removed in this commit. It was added for unclear reasons in 296b706.
-rw-r--r--src/reflect/scala/reflect/internal/Symbols.scala4
-rw-r--r--test/files/pos/sd248/Prop_1.scala2
-rw-r--r--test/files/pos/sd248/Test_2.scala5
-rw-r--r--test/files/pos/sd248/package_1.scala3
4 files changed, 11 insertions, 3 deletions
diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala
index f870ecfc15..80ccce8e83 100644
--- a/src/reflect/scala/reflect/internal/Symbols.scala
+++ b/src/reflect/scala/reflect/internal/Symbols.scala
@@ -2223,7 +2223,7 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
* to the class. As presently implemented this potentially returns class for
* any symbol except NoSymbol.
*/
- def companionClass: Symbol = flatOwnerInfo.decl(name.toTypeName).suchThat(_ isCoDefinedWith this)
+ def companionClass: Symbol = flatOwnerInfo.decl(name.toTypeName).suchThat(d => d.isClass && d.isCoDefinedWith(this))
/** For a class: the module or case class factory with the same name in the same package.
* For all others: NoSymbol
@@ -2860,8 +2860,6 @@ trait Symbols extends api.Symbols { self: SymbolTable =>
override def associatedFile_=(f: AbstractFile) { moduleClass.associatedFile = f }
override def moduleClass = referenced
- override def companionClass =
- flatOwnerInfo.decl(name.toTypeName).suchThat(sym => sym.isClass && (sym isCoDefinedWith this))
override def owner = {
if (Statistics.hotEnabled) Statistics.incCounter(ownerCount)
diff --git a/test/files/pos/sd248/Prop_1.scala b/test/files/pos/sd248/Prop_1.scala
new file mode 100644
index 0000000000..d5decda547
--- /dev/null
+++ b/test/files/pos/sd248/Prop_1.scala
@@ -0,0 +1,2 @@
+package p
+object Prop { class Whitelist }
diff --git a/test/files/pos/sd248/Test_2.scala b/test/files/pos/sd248/Test_2.scala
new file mode 100644
index 0000000000..602e6d37b5
--- /dev/null
+++ b/test/files/pos/sd248/Test_2.scala
@@ -0,0 +1,5 @@
+package p
+
+object PropTest {
+ def t = new Prop.Whitelist
+}
diff --git a/test/files/pos/sd248/package_1.scala b/test/files/pos/sd248/package_1.scala
new file mode 100644
index 0000000000..a90354e66f
--- /dev/null
+++ b/test/files/pos/sd248/package_1.scala
@@ -0,0 +1,3 @@
+package object p {
+ type Prop = String
+}