@@ -226,6 +226,10 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
226226
227227 var coDeps, contraDeps : ReverseDeps = SimpleIdentityMap .empty
228228
229+ extension (deps : ReverseDeps ) def at (param : TypeParamRef ): SimpleIdentitySet [TypeParamRef ] =
230+ val result = deps(param)
231+ if null == result then SimpleIdentitySet .empty else result
232+
229233 def dependsOn (tv : TypeVar , except : TypeVars , co : Boolean )(using Context ): Boolean =
230234 def origin (tv : TypeVar ) =
231235 assert(! tv.isInstantiated)
@@ -234,8 +238,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
234238 val excluded = except.map(origin)
235239 val qualifies : TypeParamRef => Boolean = ! excluded.contains(_)
236240 def test (deps : ReverseDeps , lens : ConstraintLens [List [TypeParamRef ]]) =
237- val depending = deps(param)
238- null != depending && depending.exists(qualifies)
241+ deps.at(param).exists(qualifies)
239242 || lens(this , tv.origin.binder, tv.origin.paramNum).exists(qualifies)
240243 // .showing(i"outer depends on $tv with ${tvdeps.toList}%, % = $result")
241244 if co then test(coDeps, upperLens) else test(contraDeps, lowerLens)
@@ -244,10 +247,8 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
244247 var add : Boolean = compiletime.uninitialized
245248
246249 def update (deps : ReverseDeps , referenced : TypeParamRef ): ReverseDeps =
247- val entry = deps(referenced)
248- val prev = if null == entry then SimpleIdentitySet .empty else entry
249- val now = if add then prev + srcParam else prev - srcParam
250- deps.updated(referenced, now)
250+ val prev = deps.at(referenced)
251+ deps.updated(referenced, if add then prev + srcParam else prev - srcParam)
251252
252253 def traverse (t : Type ) = t match
253254 case param : TypeParamRef =>
@@ -335,9 +336,9 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
335336 /** A string representing the two depenecy maps */
336337 def depsToString (using Context ): String =
337338 def depsStr (deps : ReverseDeps ): String =
338- def depStr (param : TypeParamRef ) = i " $param --> ${deps(param).nn .toList}%, % "
339- if deps.isEmpty then " " else i " \n ${deps.toList.map((k, v) => depStr(k))}% \n % "
340- i " co-deps: ${depsStr(coDeps)}\n contra -deps: ${depsStr(contraDeps)}\n "
339+ def depStr (param : TypeParamRef ) = i " $param --> ${deps.at (param).toList}%, % "
340+ if deps.isEmpty then " " else i " \n ${deps.toList.map((k, v) => depStr(k))}% \n %"
341+ i " co-deps: ${depsStr(coDeps)}\n contra -deps: ${depsStr(contraDeps)}\n "
341342
342343// ---------- Adding TypeLambdas --------------------------------------------------
343344
@@ -550,11 +551,14 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
550551 case _ =>
551552 Nil
552553
553- private def updateEntry (current : This , param : TypeParamRef , tp : Type )(using Context ): This = {
554- if Config .checkNoWildcardsInConstraint then assert(! tp.containsWildcardTypes)
555- var current1 = boundsLens.update(this , current, param, tp)
556- current1.adjustDeps(tp, current.entry(param), param)
557- tp match {
554+ private def updateEntryNoOrdering (current : This , param : TypeParamRef , newEntry : Type , oldEntry : Type )(using Context ): This =
555+ boundsLens.update(this , current, param, newEntry).adjustDeps(newEntry, oldEntry, param)
556+
557+ private def updateEntry (current : This , param : TypeParamRef , newEntry : Type )(using Context ): This = {
558+ // println(i"update $param to $tp in $current")
559+ if Config .checkNoWildcardsInConstraint then assert(! newEntry.containsWildcardTypes)
560+ var current1 = updateEntryNoOrdering(current, param, newEntry, current.entry(param))
561+ newEntry match {
558562 case TypeBounds (lo, hi) =>
559563 for p <- dependentParams(lo, isUpper = false ) do
560564 current1 = order(current1, p, param)
@@ -758,6 +762,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
758762 checkDeps(coDeps)
759763 checkDeps(contraDeps)
760764 this
765+ end checkWellFormed
761766
762767 def occursAtToplevel (param : TypeParamRef , inst : Type )(using Context ): Boolean =
763768
0 commit comments