-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Avoid junk produced by Constraint#replace. #678
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -399,7 +399,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds, | |
def removeParam(ps: List[PolyParam]) = | ||
ps.filterNot(p => p.binder.eq(poly) && p.paramNum == idx) | ||
|
||
def replaceParam(tp: Type, atPoly: PolyType, atIdx: Int) = tp match { | ||
def replaceParam(tp: Type, atPoly: PolyType, atIdx: Int): Type = tp match { | ||
case bounds @ TypeBounds(lo, hi) => | ||
|
||
def recombine(andor: AndOrType, op: (Type, Boolean) => Type, isUpper: Boolean): Type = { | ||
|
@@ -424,7 +424,8 @@ class OrderingConstraint(private val boundsMap: ParamBounds, | |
} | ||
|
||
bounds.derivedTypeBounds(replaceIn(lo, isUpper = false), replaceIn(hi, isUpper = true)) | ||
case _ => tp | ||
case _ => | ||
tp.substParam(param, replacement) | ||
} | ||
|
||
var current = | ||
|
@@ -438,8 +439,16 @@ class OrderingConstraint(private val boundsMap: ParamBounds, | |
} | ||
} | ||
|
||
def remove(pt: PolyType)(implicit ctx: Context): This = | ||
newConstraint(boundsMap.remove(pt), lowerMap.remove(pt), upperMap.remove(pt)) | ||
def remove(pt: PolyType)(implicit ctx: Context): This = { | ||
def removeFromOrdering(po: ParamOrdering) = { | ||
def removeFromBoundss(key: PolyType, bndss: Array[List[PolyParam]]): Array[List[PolyParam]] = { | ||
val bndss1 = bndss.map(bnds => bnds.filterConserve(_.binder ne pt)) | ||
if ((0 until bndss.length).forall(i => bndss(i) eq bndss1(i))) bndss else bndss1 | ||
} | ||
po.remove(pt).mapValues(removeFromBoundss) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to check the sources to find out, but I could imagine this subtle difference could get confusing when maintaining dotty. Might I suggest a different method name, like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point. In fact, I believe mapValues is the misnomer here. It should be |
||
} | ||
newConstraint(boundsMap.remove(pt), removeFromOrdering(lowerMap), removeFromOrdering(upperMap)) | ||
} | ||
|
||
def isRemovable(pt: PolyType, removedParam: Int = -1): Boolean = { | ||
val entries = boundsMap(pt) | ||
|
@@ -491,6 +500,19 @@ class OrderingConstraint(private val boundsMap: ParamBounds, | |
} | ||
} | ||
|
||
override def checkClosed()(implicit ctx: Context): Unit = { | ||
def isFreePolyParam(tp: Type) = tp match { | ||
case PolyParam(binder, _) => !contains(binder) | ||
case _ => false | ||
} | ||
def checkClosedType(tp: Type, where: String) = | ||
if (tp != null) | ||
assert(!tp.existsPart(isFreePolyParam), i"unclosed constraint: $this refers to $tp in $where") | ||
boundsMap.foreachBinding((_, tps) => tps.foreach(checkClosedType(_, "bounds"))) | ||
lowerMap.foreachBinding((_, paramss) => paramss.foreach(_.foreach(checkClosedType(_, "lower")))) | ||
upperMap.foreachBinding((_, paramss) => paramss.foreach(_.foreach(checkClosedType(_, "upper")))) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does that also work for mixed Array/List code like here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nope, it is specialized to |
||
} | ||
|
||
private var myUninstVars: mutable.ArrayBuffer[TypeVar] = _ | ||
|
||
/** The uninstantiated typevars of this constraint */ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,12 @@ object Test { | |
object Okay { | ||
Arr("1") | ||
|
||
import I.{ arrToTrav, longArrToTrav } | ||
foo(Arr("2")) | ||
} | ||
import I.{ arrToTrav, longArrToTrav } | ||
val x = foo(Arr("2")) | ||
} | ||
|
||
object Fail { | ||
import I.arrToTrav | ||
foo(Arr("3")) // found String, expected Long | ||
// import I.arrToTrav | ||
// foo(Arr("3")) // found String, expected Long | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this require further fixes before it compiles? If so, leave a breadcrumb by splitting this part out into a file in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No in fact, that code compiles. It was left commented out as an oversight. Thanks for noticing! |
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bndss.indices.forall
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I settled for: