aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/Typer.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-11-16 14:50:42 +0100
committerMartin Odersky <odersky@gmail.com>2015-11-16 14:50:42 +0100
commit10ee00edf779fbf8ad74886e523811dd96fbab5e (patch)
treedda5dced27e3cb16e2fe0c1d850ac16bd768ec68 /src/dotty/tools/dotc/typer/Typer.scala
parentd8c4ab697aa97da509bc2c943a65e4ec78917211 (diff)
downloaddotty-10ee00edf779fbf8ad74886e523811dd96fbab5e.tar.gz
dotty-10ee00edf779fbf8ad74886e523811dd96fbab5e.tar.bz2
dotty-10ee00edf779fbf8ad74886e523811dd96fbab5e.zip
Flag trailing `_' following non-function as an error
If `x` is not a function or method, then `x _` should be disallowed. scalac accepts this and converts it to () => x instead. I'd like to drop this because it's unnecessary and non-obvious. If -language:Scala2 is on, the behavior is like Scala 2's but a migration warning is issued.
Diffstat (limited to 'src/dotty/tools/dotc/typer/Typer.scala')
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index 936c006fc..b689c8750 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -1051,8 +1051,19 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
}
}
- def typedAsFunction(tree: untpd.Tree, pt: Type)(implicit ctx: Context): Tree =
- typed(tree, if (defn.isFunctionType(pt)) pt else AnyFunctionProto)
+ def typedAsFunction(tree: untpd.Tree, pt: Type)(implicit ctx: Context): Tree = {
+ val pt1 = if (defn.isFunctionType(pt)) pt else AnyFunctionProto
+ var res = typed(tree, pt1)
+ if (pt1.eq(AnyFunctionProto) && !defn.isFunctionType(res.tpe)) {
+ def msg = "not a function; cannot be followed by `_'"
+ if (ctx.scala2Mode) {
+ ctx.migrationWarning(msg, tree.pos)
+ res = typed(untpd.Function(Nil, untpd.TypedSplice(res)))
+ }
+ else ctx.error(msg, tree.pos)
+ }
+ res
+ }
/** Retrieve symbol attached to given tree */
protected def retrieveSym(tree: untpd.Tree)(implicit ctx: Context) = tree.removeAttachment(SymOfTree) match {