Skip to content

Fix to testLifted #361

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

Merged
merged 1 commit into from
Mar 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/core/TypeApplications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@ class TypeApplications(val self: Type) extends AnyVal {
* { type $hkArg$0 = T1; ...; type $hkArg$n = Tn }
*
* satisfies predicate `p`. Try base types in the order of their occurrence in `baseClasses`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The documentation still seems incomplete, we don't always check that there is a base type where the type parameters match tparams, and there's a special case when tparams.isEmpty.

* A type parameter matches a varianve V if it has V as its variance or if V == 0.
* A type parameter matches a variance V if it has V as its variance or if V == 0.
*/
def testLifted(tparams: List[Symbol], p: Type => Boolean)(implicit ctx: Context): Boolean = {
def tryLift(bcs: List[ClassSymbol]): Boolean = bcs match {
Expand All @@ -534,7 +534,7 @@ class TypeApplications(val self: Type) extends AnyVal {
false
}
if (tparams.isEmpty) false
else if (typeParams.nonEmpty) p(EtaExpand)
else if (typeParams.nonEmpty) p(EtaExpand) || tryLift(self.baseClasses)
else tryLift(self.baseClasses)
}
}
13 changes: 11 additions & 2 deletions src/dotty/tools/dotc/typer/TypeAssigner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,18 @@ trait TypeAssigner {
}
}

def avoid(tp: Type, syms: => List[Symbol])(implicit ctx: Context): Type = {
/** An upper approximation of the given type `tp` that does not refer to any symbol in `symsToAvoid`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks fine but is unrelated to the current pull request and ideally should be split in another commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but I don't have time to do that. Way too many other things on my plate :-(

* Approximation steps are:
*
* - follow aliases if the original refers to a forbidden symbol
* - widen termrefs that refer to a forbidden symbol
* - replace ClassInfos of forbidden classes by the intersection of their parents, refined by all
* non-private fields, methods, and type members.
* - drop refinements referring to a forbidden symbol.
*/
def avoid(tp: Type, symsToAvoid: => List[Symbol])(implicit ctx: Context): Type = {
val widenMap = new TypeMap {
lazy val forbidden = syms.toSet
lazy val forbidden = symsToAvoid.toSet
def toAvoid(tp: Type): Boolean = tp match {
case tp: TermRef =>
val sym = tp.symbol
Expand Down