@@ -91,24 +91,40 @@ object RefChecks {
91
91
cls.thisType
92
92
}
93
93
94
+ /** - Check that self type of `cls` conforms to self types of all `parents` as seen from
95
+ * `cls.thisType`
96
+ * - If self type of `cls` is explicit, check that it conforms to the self types
97
+ * of all its class symbols.
98
+ * @param deep If true and a self type of a parent is not given explicitly, recurse to
99
+ * check against the parents of the parent. This is needed when capture checking,
100
+ * since we assume (& check) that the capture set of an inferred self type
101
+ * is the intersection of the capture sets of all its parents
102
+ */
103
+ def checkSelfAgainstParents (cls : ClassSymbol , parents : List [Symbol ])(using Context ): Unit =
104
+ val cinfo = cls.classInfo
105
+
106
+ def checkSelfConforms (other : ClassSymbol , category : String , relation : String ) =
107
+ val otherSelf = other.declaredSelfTypeAsSeenFrom(cls.thisType)
108
+ if otherSelf.exists then
109
+ if ! (cinfo.selfType <:< otherSelf) then
110
+ report.error(DoesNotConformToSelfType (category, cinfo.selfType, cls, otherSelf, relation, other),
111
+ cls.srcPos)
112
+
113
+ for psym <- parents do
114
+ checkSelfConforms(psym.asClass, " illegal inheritance" , " parent" )
115
+ for reqd <- cls.asClass.givenSelfType.classSymbols do
116
+ if reqd != cls then
117
+ checkSelfConforms(reqd, " missing requirement" , " required" )
118
+ end checkSelfAgainstParents
119
+
94
120
/** Check that self type of this class conforms to self types of parents
95
121
* and required classes. Also check that only `enum` constructs extend
96
122
* `java.lang.Enum` and no user-written class extends ContextFunctionN.
97
123
*/
98
124
def checkParents (cls : Symbol , parentTrees : List [Tree ])(using Context ): Unit = cls.info match {
99
125
case cinfo : ClassInfo =>
100
- def checkSelfConforms (other : ClassSymbol , category : String , relation : String ) = {
101
- val otherSelf = other.declaredSelfTypeAsSeenFrom(cls.thisType)
102
- if otherSelf.exists && ! (cinfo.selfType <:< otherSelf) then
103
- report.error(DoesNotConformToSelfType (category, cinfo.selfType, cls, otherSelf, relation, other),
104
- cls.srcPos)
105
- }
106
126
val psyms = cls.asClass.parentSyms
107
- for (psym <- psyms)
108
- checkSelfConforms(psym.asClass, " illegal inheritance" , " parent" )
109
- for reqd <- cinfo.cls.givenSelfType.classSymbols do
110
- if reqd != cls then
111
- checkSelfConforms(reqd, " missing requirement" , " required" )
127
+ checkSelfAgainstParents(cls.asClass, psyms)
112
128
113
129
def isClassExtendingJavaEnum =
114
130
! cls.isOneOf(Enum | Trait ) && psyms.contains(defn.JavaEnumClass )
0 commit comments