@@ -1206,56 +1206,49 @@ object Semantic:
12061206 cls == defn.AnyValClass ||
12071207 cls == defn.ObjectClass
12081208
1209- // ----- Work list ---------------------------------------------------
1210- class WorkList private [Semantic ](tasks : List [ClassSymbol ]):
1211- /** Process the worklist until done */
1212- final def work ()(using Cache , Context ): Unit =
1213- for task <- tasks do doTask(task)
1214-
1215- /** Check an individual class
1216- *
1217- * This method should only be called from the work list scheduler.
1218- */
1219- private def doTask (classSym : ClassSymbol )(using Cache , Context ): Unit =
1220- val thisRef = ThisRef (classSym)
1221- val tpl = classSym.defTree.asInstanceOf [TypeDef ].rhs.asInstanceOf [Template ]
1209+ // ----- API --------------------------------
12221210
1223- @ tailrec
1224- def iterate (): Unit = {
1225- given Promoted = Promoted .empty(classSym)
1226- given Trace = Trace .empty.add(classSym.defTree)
1227- given reporter : Reporter .BufferedReporter = new Reporter .BufferedReporter
1211+ /** Check an individual class
1212+ *
1213+ * The class to be checked must be an instantiable concrete class.
1214+ */
1215+ private def checkClass (classSym : ClassSymbol )(using Cache , Context ): Unit =
1216+ val thisRef = ThisRef (classSym)
1217+ val tpl = classSym.defTree.asInstanceOf [TypeDef ].rhs.asInstanceOf [Template ]
12281218
1229- thisRef.ensureFresh()
1219+ @ tailrec
1220+ def iterate (): Unit = {
1221+ given Promoted = Promoted .empty(classSym)
1222+ given Trace = Trace .empty.add(classSym.defTree)
1223+ given reporter : Reporter .BufferedReporter = new Reporter .BufferedReporter
12301224
1231- // set up constructor parameters
1232- for param <- tpl.constr.termParamss.flatten do
1233- thisRef.updateField(param.symbol, Hot )
1225+ thisRef.ensureFresh()
12341226
1235- log(" checking " + classSym) { eval(tpl, thisRef, classSym) }
1236- reporter.errors.foreach(_.issue)
1227+ // set up constructor parameters
1228+ for param <- tpl.constr.termParamss.flatten do
1229+ thisRef.updateField(param.symbol, Hot )
12371230
1238- if cache.hasChanged && reporter.errors.isEmpty then
1239- // code to prepare cache and heap for next iteration
1240- cache.prepareForNextIteration()
1241- iterate()
1242- else
1243- cache.prepareForNextClass()
1244- }
1231+ log(" checking " + classSym) { eval(tpl, thisRef, classSym) }
1232+ reporter.errors.foreach(_.issue)
12451233
1246- iterate()
1247- end doTask
1248- end WorkList
1234+ if cache.hasChanged && reporter.errors.isEmpty then
1235+ // code to prepare cache and heap for next iteration
1236+ cache.prepareForNextIteration()
1237+ iterate()
1238+ else
1239+ cache.prepareForNextClass()
1240+ }
12491241
1250- // ----- API --------------------------------
1242+ iterate()
1243+ end checkClass
12511244
12521245 /**
12531246 * Check the specified concrete classes
12541247 */
1255- def checkClasses (concreteClasses : List [ClassSymbol ])(using Context ): Unit =
1256- val workList = new WorkList (concreteClasses )
1257- val cache = new Cache
1258- workList.work()( using cache, ctx )
1248+ def checkClasses (classes : List [ClassSymbol ])(using Context ): Unit =
1249+ given Cache ( )
1250+ for classSym <- classes if isConcreteClass(classSym) do
1251+ checkClass(classSym )
12591252
12601253// ----- Semantic definition --------------------------------
12611254
@@ -1766,3 +1759,18 @@ object Semantic:
17661759 if (sym.isEffectivelyFinal || sym.isConstructor) sym
17671760 else sym.matchingMember(cls.appliedRef)
17681761 }
1762+
1763+ private def isConcreteClass (cls : ClassSymbol )(using Context ) = {
1764+ val instantiable : Boolean =
1765+ cls.is(Flags .Module ) ||
1766+ ! cls.isOneOf(Flags .AbstractOrTrait ) && {
1767+ // see `Checking.checkInstantiable` in typer
1768+ val tp = cls.appliedRef
1769+ val stp = SkolemType (tp)
1770+ val selfType = cls.givenSelfType.asSeenFrom(stp, cls)
1771+ ! selfType.exists || stp <:< selfType
1772+ }
1773+
1774+ // A concrete class may not be instantiated if the self type is not satisfied
1775+ instantiable && cls.enclosingPackageClass != defn.StdLibPatchesPackage .moduleClass
1776+ }
0 commit comments