aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/dotty/tools/dotc/typer/Typer.scala4
-rw-r--r--tests/neg/i941.scala9
-rw-r--r--tests/pos/i941.scala10
3 files changed, 21 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala
index b689c8750..d54c9f731 100644
--- a/src/dotty/tools/dotc/typer/Typer.scala
+++ b/src/dotty/tools/dotc/typer/Typer.scala
@@ -1054,8 +1054,8 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
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 (pt1.eq(AnyFunctionProto) && !defn.isFunctionClass(res.tpe.classSymbol)) {
+ def msg = i"not a function: ${res.tpe}; cannot be followed by `_'"
if (ctx.scala2Mode) {
ctx.migrationWarning(msg, tree.pos)
res = typed(untpd.Function(Nil, untpd.TypedSplice(res)))
diff --git a/tests/neg/i941.scala b/tests/neg/i941.scala
new file mode 100644
index 000000000..2643c2546
--- /dev/null
+++ b/tests/neg/i941.scala
@@ -0,0 +1,9 @@
+object Test {
+
+ def bar(tl: => String) = {
+ val x = tl _ //error
+ val y = x _ // error
+ val s: String = x() // error
+ }
+
+}
diff --git a/tests/pos/i941.scala b/tests/pos/i941.scala
new file mode 100644
index 000000000..75bf4e448
--- /dev/null
+++ b/tests/pos/i941.scala
@@ -0,0 +1,10 @@
+object Test {
+
+ class C[A] {
+
+ def this(y: A) = { this(); foo(y) }
+
+ def foo(x: A): Unit = ()
+
+ }
+}