diff options
author | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-11-04 15:19:41 +0100 |
---|---|---|
committer | Dmitry Petrashko <dmitry.petrashko@gmail.com> | 2014-11-22 20:10:22 +0100 |
commit | 32954ba55955f4335bb34007269e3d405faa1780 (patch) | |
tree | 4410a4a406fd5dceb97a74b3a1df78bc0d4d8c5c /src/dotty/tools/dotc/ast/tpd.scala | |
parent | cc8ca00fc1718bcbb49e3c61f3c0682eac2a7e7c (diff) | |
download | dotty-32954ba55955f4335bb34007269e3d405faa1780.tar.gz dotty-32954ba55955f4335bb34007269e3d405faa1780.tar.bz2 dotty-32954ba55955f4335bb34007269e3d405faa1780.zip |
Extracting ApplyOverloaded to be reused in UnPickler and ClassfileParser
Diffstat (limited to 'src/dotty/tools/dotc/ast/tpd.scala')
-rw-r--r-- | src/dotty/tools/dotc/ast/tpd.scala | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala index c735f079c..9bf19dc5c 100644 --- a/src/dotty/tools/dotc/ast/tpd.scala +++ b/src/dotty/tools/dotc/ast/tpd.scala @@ -2,6 +2,7 @@ package dotty.tools package dotc package ast +import dotty.tools.dotc.typer.ProtoTypes.FunProtoTyped import transform.SymUtils._ import core._ import util.Positions._, Types._, Contexts._, Constants._, Names._, Flags._ @@ -677,6 +678,23 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { Throw(New(defn.ClassCastExceptionClass.typeRef, Nil)) withPos tree.pos } } + + def applyOverloaded(receiver: Tree, method: TermName, args: List[Tree], targs: List[Type], expectedType: Type)(implicit ctx: Context): Tree = { + val typer = ctx.typer + val proto = new FunProtoTyped(args, expectedType, typer) + val alts = receiver.tpe.member(method).alternatives.map(_.termRef) + + val alternatives = ctx.typer.resolveOverloaded(alts, proto, Nil) + assert(alternatives.size == 1) // this is parsed from bytecode tree. there's nothing user can do about it + + val selected = alternatives.head + val fun = receiver + .select(TermRef.withSig(receiver.tpe.normalizedPrefix, selected.termSymbol.asTerm)) + .appliedToTypes(targs) + val apply = untpd.Apply(fun, args) + + new typer.ApplyToTyped(apply, fun, selected, args, expectedType).result.asInstanceOf[Tree] // needed to handle varargs + } @tailrec def sameTypes(trees: List[tpd.Tree], trees1: List[tpd.Tree]): Boolean = { |