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 {
1808
1808
case class ClassAndCompanionNameClash (cls : Symbol , other : Symbol )(implicit ctx : Context )
1809
1809
extends Message (ClassAndCompanionNameClashID ) {
1810
1810
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 }"
1812
1812
val explanation = {
1813
1813
val kind = if (cls.owner.is(Flags .Trait )) " trait" else " class"
1814
1814
Original file line number Diff line number Diff line change @@ -112,10 +112,15 @@ object RefChecks {
112
112
* a class or module with same name
113
113
*/
114
114
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 =>
118
122
ctx.error(ClassAndCompanionNameClash (cls, other), cls.pos)
123
+ }
119
124
}
120
125
121
126
// 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