aboutsummaryrefslogtreecommitdiff
path: root/compiler/src/dotty/tools/dotc/typer/Applications.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2017-02-21 15:23:35 +0100
committerMartin Odersky <odersky@gmail.com>2017-02-21 15:35:17 +0100
commitf37b2a1dcddd2fdb8be0f703e3feb9e3c2630514 (patch)
tree95dca553db0786275cfc023028a445859b637062 /compiler/src/dotty/tools/dotc/typer/Applications.scala
parent9f879c1677b467037f6c19cc0abe43e0adb802fa (diff)
downloaddotty-f37b2a1dcddd2fdb8be0f703e3feb9e3c2630514.tar.gz
dotty-f37b2a1dcddd2fdb8be0f703e3feb9e3c2630514.tar.bz2
dotty-f37b2a1dcddd2fdb8be0f703e3feb9e3c2630514.zip
Add overloading support for case-closures
case-closures (which are represented as Match nodes) have a known arity just like other function literals. So shape analysis for overloading resolution should apply to them as well.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/typer/Applications.scala')
-rw-r--r--compiler/src/dotty/tools/dotc/typer/Applications.scala9
1 files changed, 8 insertions, 1 deletions
diff --git a/compiler/src/dotty/tools/dotc/typer/Applications.scala b/compiler/src/dotty/tools/dotc/typer/Applications.scala
index 0ed6ed6b4..2cfe01616 100644
--- a/compiler/src/dotty/tools/dotc/typer/Applications.scala
+++ b/compiler/src/dotty/tools/dotc/typer/Applications.scala
@@ -1227,6 +1227,8 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
def typeShape(tree: untpd.Tree): Type = tree match {
case untpd.Function(args, body) =>
defn.FunctionOf(args map Function.const(defn.AnyType), typeShape(body))
+ case Match(EmptyTree, _) =>
+ defn.PartialFunctionType.appliedTo(defn.AnyType :: defn.NothingType :: Nil)
case _ =>
defn.NothingType
}
@@ -1270,8 +1272,13 @@ trait Applications extends Compatibility { self: Typer with Dynamic =>
def narrowBySize(alts: List[TermRef]): List[TermRef] =
alts filter (alt => sizeFits(alt, alt.widen))
+ def isFunArg(arg: untpd.Tree) = arg match {
+ case untpd.Function(_, _) | Match(EmptyTree, _) => true
+ case _ => false
+ }
+
def narrowByShapes(alts: List[TermRef]): List[TermRef] = {
- if (normArgs exists (_.isInstanceOf[untpd.Function]))
+ if (normArgs exists isFunArg)
if (hasNamedArg(args)) narrowByTrees(alts, args map treeShape, resultType)
else narrowByTypes(alts, normArgs map typeShape, resultType)
else