diff options
author | Martin Odersky <odersky@gmail.com> | 2014-05-18 16:36:20 +0200 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2014-05-30 14:43:39 +0200 |
commit | 70e785f5d8a583dae127dadf4d9add70bdea71f7 (patch) | |
tree | 62067ce7094f2aead1e7977f7be118ac157c04fe /src/dotty/tools/dotc | |
parent | c70366db8469e81e315fe89672e8321607a7310a (diff) | |
download | dotty-70e785f5d8a583dae127dadf4d9add70bdea71f7.tar.gz dotty-70e785f5d8a583dae127dadf4d9add70bdea71f7.tar.bz2 dotty-70e785f5d8a583dae127dadf4d9add70bdea71f7.zip |
Simplify result handling in FunProto.
Following the example of SelectionProto, we now always hide the result in a FunProto
behind an IgnoreProto. This avoids a special case retry with a weaker FunProto in
tryInsertApplyOrImplicit.
Diffstat (limited to 'src/dotty/tools/dotc')
-rw-r--r-- | src/dotty/tools/dotc/typer/Applications.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/ProtoTypes.scala | 5 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 30 |
3 files changed, 7 insertions, 32 deletions
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index 023063585..aaceac0e0 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -441,7 +441,7 @@ trait Applications extends Compatibility { self: Typer => def typedApply(tree: untpd.Apply, pt: Type)(implicit ctx: Context): Tree = { def realApply(implicit ctx: Context): Tree = track("realApply") { - var proto = new FunProto(tree.args, ignoreIfProto(pt), this) + var proto = new FunProto(tree.args, IgnoredProto(pt), this) val fun1 = typedExpr(tree.fun, proto) // Warning: The following line is dirty and fragile. We record that auto-tupling was demanded as @@ -461,7 +461,7 @@ trait Applications extends Compatibility { self: Typer => val result = app.result ConstFold(result) } { (failedVal, failedState) => - val fun2 = tryInsertImplicits(fun1, proto) + val fun2 = tryInsertImplicitOnQualifier(fun1, proto) if (fun1 eq fun2) { failedState.commit() failedVal diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala index 76fe1af31..19d8d6895 100644 --- a/src/dotty/tools/dotc/typer/ProtoTypes.scala +++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala @@ -83,11 +83,6 @@ object ProtoTypes { override def deepenProto(implicit ctx: Context): Type = ignored } - def ignoreIfProto(tp: Type): Type = tp match { - case proto: ProtoType => IgnoredProto(proto) - case _ => tp - } - /** A prototype for expressions [] that are part of a selection operation: * * [ ].name: proto diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index 0293d1803..d6b724270 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -1014,20 +1014,12 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit } } - private def noResultProto(pt: Type) = pt match { - case pt: FunProto => pt.derivedFunProto(pt.args, WildcardType, pt.typer) // drop result type, because views are disabled - case _ => pt - } - - /** Add apply node or implicit conversions. Three strategies are tried, and the first - * that is succesful is picked. If none of the strategies are succesful, continues with + /** Add apply node or implicit conversions. Two strategies are tried, and the first + * that is succesful is picked. If neither of the strategies are succesful, continues with * `fallBack`. * * 1st strategy: Try to insert `.apply` so that the result conforms to prototype `pt`. - * 2nd strategy: If the expected type is a FunProto with a non-wildcard resulttype, - * try to match against the FunProto with wildcard resulttype (this allows for an additional - * implicit conversion on the result). - * 3rd stratgey: If tree is a select `qual.name`, try to insert an implicit conversion + * 2nd stratgey: If tree is a select `qual.name`, try to insert an implicit conversion * around the qualifier part `qual` so that the result conforms to the expected type * with wildcard result type. */ @@ -1036,23 +1028,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit val sel = typedSelect(untpd.Select(untpd.TypedSplice(tree), nme.apply), pt) if (sel.tpe.isError) sel else adapt(sel, pt) } { (failedTree, failedState) => - val tree1 = tryInsertImplicits(tree, pt) + val tree1 = tryInsertImplicitOnQualifier(tree, pt) if (tree1 eq tree) fallBack(failedTree, failedState) - else adapt(tree1, noResultProto(pt)) + else adapt(tree1, pt) } - def tryInsertImplicits(tree: Tree, pt: ProtoType)(implicit ctx: Context): Tree = { - val normalizedProto = noResultProto(pt) - if (normalizedProto eq pt) tryInsertImplicitOnQualifier(tree, pt) - else tryEither { implicit ctx => - val tree1 = adaptInterpolated(tree, normalizedProto, EmptyTree) - if (tree1 eq tree) ctx.error("no progress") - tree1 - } { (_, _) => - tryInsertImplicitOnQualifier(tree, normalizedProto) - } - } - /** If this tree is a select node `qual.name`, try to insert an implicit conversion * `c` around `qual` so that `c(qual).name` conforms to `pt`. If that fails * return `tree` itself. |