File tree Expand file tree Collapse file tree 3 files changed +24
-4
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 3 files changed +24
-4
lines changed Original file line number Diff line number Diff line change @@ -1808,7 +1808,7 @@ object messages {
18081808 case class ClassAndCompanionNameClash (cls : Symbol , other : Symbol )(implicit ctx : Context )
18091809 extends Message (ClassAndCompanionNameClashID ) {
18101810 val kind = " Naming"
1811- val msg = hl " Name clash: both ${cls.owner} and its companion object defines ${cls.name}"
1811+ val msg = hl " Name clash: both ${cls.owner} and its companion object defines ${cls.name.stripModuleClassSuffix }"
18121812 val explanation = {
18131813 val kind = if (cls.owner.is(Flags .Trait )) " trait" else " class"
18141814
Original file line number Diff line number Diff line change @@ -112,10 +112,15 @@ object RefChecks {
112112 * a class or module with same name
113113 */
114114 private def checkCompanionNameClashes (cls : Symbol )(implicit ctx : Context ): Unit =
115- if (! (cls.owner is ModuleClass )) {
116- val other = cls.owner.linkedClass.info.decl(cls.name).symbol
117- if (other.isClass)
115+ if (! cls.owner.is(ModuleClass )) {
116+ def clashes (sym : Symbol ) =
117+ sym.isClass &&
118+ sym.name.stripModuleClassSuffix == cls.name.stripModuleClassSuffix
119+
120+ val others = cls.owner.linkedClass.info.decls.filter(clashes)
121+ others.foreach { other =>
118122 ctx.error(ClassAndCompanionNameClash (cls, other), cls.pos)
123+ }
119124 }
120125
121126 // Override checking ------------------------------------------------------------
Original file line number Diff line number Diff line change 1+ object Test {
2+ object Foo
3+ }
4+
5+ class Test {
6+ class Foo // error: name clash
7+ }
8+
9+ object Test2 {
10+ class Foo
11+ }
12+
13+ class Test2 {
14+ object Foo // error: name clash
15+ }
You can’t perform that action at this time.
0 commit comments