File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
compiler/src/dotty/tools/dotc/typer Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -1316,12 +1316,27 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1316
1316
result
1317
1317
}
1318
1318
1319
+ /** Checks if one of the decls is a type with the same name as class type member in selfType */
1320
+ def classExistsOnSelf (decls : Scope , selfType : Type ): Boolean = {
1321
+ if (! selfType.exists || (selfType.classSymbol eq cls)) false
1322
+ else {
1323
+ def memberInSelfButNotThis (decl : Symbol ) =
1324
+ selfType.member(decl.name).symbol.filter(other => other.isClass && other.owner != cls)
1325
+ decls.iterator.filter(_.isType).foldLeft(false ) { (foundRedef, decl) =>
1326
+ val other = memberInSelfButNotThis(decl)
1327
+ if (other.exists)
1328
+ ctx.error(CannotHaveSameNameAs (decl, other), decl.pos)
1329
+ foundRedef || other.exists
1330
+ }
1331
+ }
1332
+ }
1333
+
1319
1334
completeAnnotations(cdef, cls)
1320
1335
val constr1 = typed(constr).asInstanceOf [DefDef ]
1321
1336
val parentsWithClass = ensureFirstIsClass(parents mapconserve typedParent, cdef.namePos)
1322
1337
val parents1 = ensureConstrCall(cls, parentsWithClass)(superCtx)
1323
1338
val self1 = typed(self)(ctx.outer).asInstanceOf [ValDef ] // outer context where class members are not visible
1324
- if (self1.tpt.tpe.isError) {
1339
+ if (self1.tpt.tpe.isError || classExistsOnSelf(cls.unforcedDecls, self1.tpt.tpe) ) {
1325
1340
// fail fast to avoid typing the body with an error type
1326
1341
cdef.withType(UnspecifiedErrorType )
1327
1342
} else {
Original file line number Diff line number Diff line change
1
+ trait Foo { trait Inner }
2
+ trait Bar { foo : Foo =>
3
+ type Inner <: foo.Inner // error: type Inner cannot have the same name as trait Inner in trait Foo -- class definitions cannot be overridden
4
+ }
5
+ trait Baz { baz : Foo =>
6
+ class Inner // error: class Inner cannot have the same name as trait Inner in trait Foo -- class definitions cannot be overridden
7
+ }
You can’t perform that action at this time.
0 commit comments