diff options
author | Martin Odersky <odersky@gmail.com> | 2016-11-11 14:53:57 +0100 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2016-11-11 14:53:57 +0100 |
commit | 987c5905b1024aa9e62ac72aee2d1d6f63cb2110 (patch) | |
tree | 5a5e800520cfd466f37733291e0627bc5e6f8405 | |
parent | 28c2e04dd33b6389a44460f977a97b8691265994 (diff) | |
download | dotty-987c5905b1024aa9e62ac72aee2d1d6f63cb2110.tar.gz dotty-987c5905b1024aa9e62ac72aee2d1d6f63cb2110.tar.bz2 dotty-987c5905b1024aa9e62ac72aee2d1d6f63cb2110.zip |
Add assignType for RefinedTypeTrees
If we want to pickle type trees, we need a type assigner
for RefinedTypeTree.
-rw-r--r-- | src/dotty/tools/dotc/typer/TypeAssigner.scala | 13 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 15 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/dotty/tools/dotc/typer/TypeAssigner.scala b/src/dotty/tools/dotc/typer/TypeAssigner.scala index b1fed308c..259b3b83e 100644 --- a/src/dotty/tools/dotc/typer/TypeAssigner.scala +++ b/src/dotty/tools/dotc/typer/TypeAssigner.scala @@ -431,7 +431,18 @@ trait TypeAssigner { def assignType(tree: untpd.OrTypeTree, left: Tree, right: Tree)(implicit ctx: Context) = tree.withType(left.tpe | right.tpe) - // RefinedTypeTree is missing, handled specially in Typer and Unpickler. + /** Assign type of RefinedType. + * Refinements are typed as if they were members of refinement class `refineCls`. + */ + def assignType(tree: untpd.RefinedTypeTree, parent: Tree, refinements: List[Tree], refineCls: ClassSymbol)(implicit ctx: Context) = { + def addRefinement(parent: Type, refinement: Tree): Type = { + val rsym = refinement.symbol + val rinfo = if (rsym is Accessor) rsym.info.resultType else rsym.info + RefinedType(parent, rsym.name, rinfo) + } + val refined = (parent.tpe /: refinements)(addRefinement) + tree.withType(RecType.closeOver(rt => refined.substThis(refineCls, RecThis(rt)))) + } def assignType(tree: untpd.AppliedTypeTree, tycon: Tree, args: List[Tree])(implicit ctx: Context) = { val tparams = tycon.tpe.typeParams diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index a93262314..6b69a859e 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1008,23 +1008,16 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit val refineCls = createSymbol(refineClsDef).asClass val TypeDef(_, impl: Template) = typed(refineClsDef) val refinements1 = impl.body - val seen = mutable.Set[Symbol]() assert(tree.refinements.length == refinements1.length, s"${tree.refinements} != $refinements1") - def addRefinement(parent: Type, refinement: Tree): Type = { + val seen = mutable.Set[Symbol]() + for (refinement <- refinements1) { // TODO: get clarity whether we want to enforce these conditions typr.println(s"adding refinement $refinement") checkRefinementNonCyclic(refinement, refineCls, seen) val rsym = refinement.symbol if (rsym.is(Method) && rsym.allOverriddenSymbols.isEmpty) - ctx.error(i"refinement $rsym without matching type in parent $parent", refinement.pos) - val rinfo = if (rsym is Accessor) rsym.info.resultType else rsym.info - RefinedType(parent, rsym.name, rinfo) - // todo later: check that refinement is within bounds + ctx.error(i"refinement $rsym without matching type in parent $tpt1", refinement.pos) } - val refined = (tpt1.tpe /: refinements1)(addRefinement) - val res = cpy.RefinedTypeTree(tree)(tpt1, refinements1).withType( - RecType.closeOver(rt => refined.substThis(refineCls, RecThis(rt)))) - typr.println(i"typed refinement: ${res.tpe}") - res + assignType(cpy.RefinedTypeTree(tree)(tpt1, refinements1), tpt1, refinements1, refineCls) } def typedAppliedTypeTree(tree: untpd.AppliedTypeTree)(implicit ctx: Context): Tree = track("typedAppliedTypeTree") { |