From bd1858896f6546d778aa93c39b491ed5e2d7e0b3 Mon Sep 17 00:00:00 2001 From: Lukas Rytz Date: Wed, 26 Oct 2016 16:43:36 +0200 Subject: 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. --- src/reflect/scala/reflect/internal/Symbols.scala | 4 +--- test/files/pos/sd248/Prop_1.scala | 2 ++ test/files/pos/sd248/Test_2.scala | 5 +++++ test/files/pos/sd248/package_1.scala | 3 +++ 4 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 test/files/pos/sd248/Prop_1.scala create mode 100644 test/files/pos/sd248/Test_2.scala create mode 100644 test/files/pos/sd248/package_1.scala 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 +} -- cgit v1.2.3