Fix Substitution for Wildcard types

This commit is contained in:
Andreas Stadelmeier 2024-03-27 14:07:01 +01:00
parent 31349bbda8
commit 6538be956f

View File

@ -25,8 +25,8 @@ sealed abstract class Type:
}
}
def substitute(substMap: Map[Type,Type]): Type = {
def substituteWCB(wcb: WildcardBound) =
WildcardBound(wcb.name, wcb.upper.substitute(substMap), wcb.lower.substitute(substMap))
def substituteWCB(wcb: WildcardBound, map: Map[Type,Type]) =
WildcardBound(wcb.name, wcb.upper.substitute(map), wcb.lower.substitute(map))
val replace = substMap.get(this)
if (replace.isDefined) {
@ -34,8 +34,10 @@ sealed abstract class Type:
} else {
this match {
case RefType(wildcards, name, params) =>
val newlyDefinedWCs = wildcards.getWildcards()
val reducedMap = substMap.filter(p => p._1.isInstanceOf[Wildcard] && !newlyDefinedWCs.contains(p._1.asInstanceOf[Wildcard]))
RefType(
WildcardEnvironment(wildcards.map(substituteWCB)), name, params.map(_.substitute(substMap)))
WildcardEnvironment(wildcards.map(substituteWCB(_, reducedMap))), name, params.map(_.substitute(substMap)))
case t => t
}
}