aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorodersky <odersky@gmail.com>2016-07-21 15:57:02 +0200
committerGitHub <noreply@github.com>2016-07-21 15:57:02 +0200
commit80a65f4b2512bdf1dc46144bea1c000d39319872 (patch)
tree3153a177e298d5416a0a187163a48d4ba6503154 /src
parent990663624bdaa93bd7db5f64be78f3ca26d59633 (diff)
parent9ccb47ae2e9ae34a0ebd6bafbf6f327b39fc8d4a (diff)
downloaddotty-80a65f4b2512bdf1dc46144bea1c000d39319872.tar.gz
dotty-80a65f4b2512bdf1dc46144bea1c000d39319872.tar.bz2
dotty-80a65f4b2512bdf1dc46144bea1c000d39319872.zip
Merge pull request #1395 from dotty-staging/fix-#1378
Fix #1378: Propagate more knowledge of result type into applications
Diffstat (limited to 'src')
-rw-r--r--src/dotty/tools/dotc/ast/TreeInfo.scala13
-rw-r--r--src/dotty/tools/dotc/core/Constants.scala4
-rw-r--r--src/dotty/tools/dotc/typer/Applications.scala9
-rw-r--r--src/dotty/tools/dotc/typer/ProtoTypes.scala2
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala10
5 files changed, 34 insertions, 4 deletions
diff --git a/src/dotty/tools/dotc/ast/TreeInfo.scala b/src/dotty/tools/dotc/ast/TreeInfo.scala
index c1efd0b0b..a48651ebf 100644
--- a/src/dotty/tools/dotc/ast/TreeInfo.scala
+++ b/src/dotty/tools/dotc/ast/TreeInfo.scala
@@ -278,7 +278,18 @@ trait TreeInfo[T >: Untyped <: Type] { self: Trees.Instance[T] =>
}
trait UntypedTreeInfo extends TreeInfo[Untyped] { self: Trees.Instance[Untyped] =>
- // todo: fill with methods from TreeInfo that only apply to untpd.Tree's
+ import TreeInfo._
+
+ def isFunctionWithUnknownParamType(tree: Tree) = tree match {
+ case untpd.Function(args, _) =>
+ args.exists {
+ case ValDef(_, tpt, _) => tpt.isEmpty
+ case _ => false
+ }
+ case _ => false
+ }
+
+ // todo: fill with other methods from TreeInfo that only apply to untpd.Tree's
}
trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
diff --git a/src/dotty/tools/dotc/core/Constants.scala b/src/dotty/tools/dotc/core/Constants.scala
index 0f8c68bad..1892e4bdc 100644
--- a/src/dotty/tools/dotc/core/Constants.scala
+++ b/src/dotty/tools/dotc/core/Constants.scala
@@ -173,8 +173,8 @@ object Constants {
ctx.typerState.constraint.entry(param) match {
case TypeBounds(lo, hi) =>
if (hi.classSymbol.isPrimitiveValueClass) hi //constrain further with high bound
- else lo
- case NoType => param.binder.paramBounds(param.paramNum).lo
+ else classBound(lo)
+ case NoType => classBound(param.binder.paramBounds(param.paramNum).lo)
case inst => classBound(inst)
}
case pt => pt
diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala
index 69ad4f107..f0a514e8c 100644
--- a/src/dotty/tools/dotc/typer/Applications.scala
+++ b/src/dotty/tools/dotc/typer/Applications.scala
@@ -553,6 +553,15 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
// a modified tree but this would be more convoluted and less efficient.
if (proto.isTupled) proto = proto.tupled
+ // If some of the application's arguments are function literals without explicitly declared
+ // parameter types, relate the normalized result type of the application with the
+ // expected type through `constrainResult`. This can add more constraints which
+ // help sharpen the inferred parameter types for the argument function literal(s).
+ // This tweak is needed to make i1378 compile.
+ if (tree.args.exists(untpd.isFunctionWithUnknownParamType(_)))
+ if (!constrainResult(fun1.tpe.widen, proto.derivedFunProto(resultType = pt)))
+ typr.println(i"result failure for $tree with type ${fun1.tpe.widen}, expected = $pt")
+
fun1.tpe match {
case ErrorType => tree.withType(ErrorType)
case TryDynamicCallType =>
diff --git a/src/dotty/tools/dotc/typer/ProtoTypes.scala b/src/dotty/tools/dotc/typer/ProtoTypes.scala
index a430d5f75..767ccbe7d 100644
--- a/src/dotty/tools/dotc/typer/ProtoTypes.scala
+++ b/src/dotty/tools/dotc/typer/ProtoTypes.scala
@@ -175,7 +175,7 @@ object ProtoTypes {
def isMatchedBy(tp: Type)(implicit ctx: Context) =
typer.isApplicable(tp, Nil, typedArgs, resultType)
- def derivedFunProto(args: List[untpd.Tree], resultType: Type, typer: Typer) =
+ def derivedFunProto(args: List[untpd.Tree] = this.args, resultType: Type, typer: Typer = this.typer) =
if ((args eq this.args) && (resultType eq this.resultType) && (typer eq this.typer)) this
else new FunProto(args, resultType, typer)
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index df72f0095..e982f9aa9 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -600,6 +600,16 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
untpd.TypeTree(defn.FunctionClass(args.length).typeRef), args :+ body), pt)
else {
val params = args.asInstanceOf[List[untpd.ValDef]]
+
+ pt match {
+ case pt: TypeVar if untpd.isFunctionWithUnknownParamType(tree) =>
+ // try to instantiate `pt` if this is possible. If it does not
+ // work the error will be reported later in `inferredParam`,
+ // when we try to infer the parameter type.
+ isFullyDefined(pt, ForceDegree.noBottom)
+ case _ =>
+ }
+
val (protoFormals, protoResult) = decomposeProtoFunction(pt, params.length)
def refersTo(arg: untpd.Tree, param: untpd.ValDef): Boolean = arg match {