diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2015-10-09 14:28:52 +0200 |
---|---|---|
committer | Guillaume Martres <smarter@ubuntu.com> | 2015-10-09 14:39:43 +0200 |
commit | bea9aa282c7a929fdab815b3f34d2d697ade7bca (patch) | |
tree | e635bd068d2c48c5d00679f2d7dc65900796aec5 /src/dotty/tools/dotc/typer/Inferencing.scala | |
parent | 8532c98672e6dcde4d350f253b46892cc0ece34c (diff) | |
download | dotty-bea9aa282c7a929fdab815b3f34d2d697ade7bca.tar.gz dotty-bea9aa282c7a929fdab815b3f34d2d697ade7bca.tar.bz2 dotty-bea9aa282c7a929fdab815b3f34d2d697ade7bca.zip |
Move Inferencing out of the Typer cake
Diffstat (limited to 'src/dotty/tools/dotc/typer/Inferencing.scala')
-rw-r--r-- | src/dotty/tools/dotc/typer/Inferencing.scala | 43 |
1 files changed, 1 insertions, 42 deletions
diff --git a/src/dotty/tools/dotc/typer/Inferencing.scala b/src/dotty/tools/dotc/typer/Inferencing.scala index 0a76f45c5..81a302717 100644 --- a/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/src/dotty/tools/dotc/typer/Inferencing.scala @@ -20,7 +20,7 @@ import config.Printers._ import annotation.tailrec import collection.mutable -trait Inferencing { this: Checking => +object Inferencing { import tpd._ @@ -197,47 +197,6 @@ trait Inferencing { this: Checking => case _ => NoType } - /** Ensure that the first type in a list of parent types Ps points to a non-trait class. - * If that's not already the case, add one. The added class type CT is determined as follows. - * First, let C be the unique class such that - * - there is a parent P_i such that P_i derives from C, and - * - for every class D: If some parent P_j, j <= i derives from D, then C derives from D. - * Then, let CT be the smallest type which - * - has C as its class symbol, and - * - for all parents P_i: If P_i derives from C then P_i <:< CT. - */ - def ensureFirstIsClass(parents: List[Type])(implicit ctx: Context): List[Type] = { - def realClassParent(cls: Symbol): ClassSymbol = - if (!cls.isClass) defn.ObjectClass - else if (!(cls is Trait)) cls.asClass - else cls.asClass.classParents match { - case parentRef :: _ => realClassParent(parentRef.symbol) - case nil => defn.ObjectClass - } - def improve(candidate: ClassSymbol, parent: Type): ClassSymbol = { - val pcls = realClassParent(parent.classSymbol) - if (pcls derivesFrom candidate) pcls else candidate - } - parents match { - case p :: _ if p.classSymbol.isRealClass => parents - case _ => - val pcls = (defn.ObjectClass /: parents)(improve) - typr.println(i"ensure first is class $parents%, % --> ${parents map (_ baseTypeWithArgs pcls)}%, %") - val ptype = ctx.typeComparer.glb( - defn.ObjectType :: (parents map (_ baseTypeWithArgs pcls))) - ptype :: parents - } - } - - /** Ensure that first parent tree refers to a real class. */ - def ensureFirstIsClass(parents: List[Tree], pos: Position)(implicit ctx: Context): List[Tree] = parents match { - case p :: ps if p.tpe.classSymbol.isRealClass => parents - case _ => - // add synthetic class type - val first :: _ = ensureFirstIsClass(parents.tpes) - TypeTree(checkFeasible(first, pos, d"\n in inferred parent $first")).withPos(pos) :: parents - } - /** Interpolate those undetermined type variables in the widened type of this tree * which are introduced by type application contained in the tree. * If such a variable appears covariantly in type `tp` or does not appear at all, |