File tree 3 files changed +17
-7
lines changed
src/dotty/tools/dotc/typer
3 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -71,14 +71,20 @@ object RefChecks {
71
71
}
72
72
}
73
73
74
- /** Check that self type of this class conforms to self types of parents */
75
- private def checkSelfType (clazz : Symbol )(implicit ctx : Context ): Unit = clazz.info match {
74
+ /** Check that self type of this class conforms to self types of parents
75
+ * and required classes.
76
+ */
77
+ private def checkSelfType (cls : Symbol )(implicit ctx : Context ): Unit = cls.info match {
76
78
case cinfo : ClassInfo =>
77
- for (parent <- cinfo.classParents) {
78
- val pself = parent .givenSelfType.asSeenFrom(clazz .thisType, parent .classSymbol)
79
- if (pself .exists && ! (cinfo.selfType <:< pself ))
80
- ctx.error(d " illegal inheritance : self type ${cinfo.selfType} of $clazz does not conform to self type $pself of parent ${parent .classSymbol}" , clazz .pos)
79
+ def checkSelfConforms ( other : TypeRef , category : String , relation : String ) = {
80
+ val otherSelf = other .givenSelfType.asSeenFrom(cls .thisType, other .classSymbol)
81
+ if (otherSelf .exists && ! (cinfo.selfType <:< otherSelf ))
82
+ ctx.error(d " $category : self type ${cinfo.selfType} of $cls does not conform to self type $otherSelf of $relation ${other .classSymbol}" , cls .pos)
81
83
}
84
+ for (parent <- cinfo.classParents)
85
+ checkSelfConforms(parent, " illegal inheritance" , " parent" )
86
+ for (reqd <- cinfo.givenSelfType.classSymbols)
87
+ checkSelfConforms(reqd.typeRef, " missing requirement" , " required" )
82
88
case _ =>
83
89
}
84
90
Original file line number Diff line number Diff line change @@ -136,7 +136,7 @@ class tests extends CompilerTest {
136
136
@ Test def neg_moduleSubtyping = compileFile(negDir, " moduleSubtyping" , xerrors = 4 )
137
137
@ Test def neg_escapingRefs = compileFile(negDir, " escapingRefs" , xerrors = 2 )
138
138
@ Test def neg_instantiateAbstract = compileFile(negDir, " instantiateAbstract" , xerrors = 8 )
139
- @ Test def neg_selfInheritance = compileFile(negDir, " selfInheritance" , xerrors = 5 )
139
+ @ Test def neg_selfInheritance = compileFile(negDir, " selfInheritance" , xerrors = 6 )
140
140
@ Test def neg_selfreq = compileFile(negDir, " selfreq" , xerrors = 4 )
141
141
@ Test def neg_shadowedImplicits = compileFile(negDir, " arrayclone-new" , xerrors = 2 )
142
142
@ Test def neg_traitParamsTyper = compileFile(negDir, " traitParamsTyper" , xerrors = 5 )
Original file line number Diff line number Diff line change @@ -26,3 +26,7 @@ object Test {
26
26
object M extends C // error
27
27
28
28
}
29
+
30
+ trait X { self : Y => }
31
+ trait Y { self : Z => }
32
+ trait Z
You can’t perform that action at this time.
0 commit comments