From b95ca32062ae980fb45b3e93d8c90219bc1d2530 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Mon, 25 Mar 2013 12:40:48 +0100 Subject: SI-7299 Improve error message for eta-expanding 23+ param method Before, we got `error: missing arguments for method f`. --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 10 ++++++++-- test/files/neg/t7299.check | 7 +++++++ test/files/neg/t7299.scala | 6 ++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/files/neg/t7299.check create mode 100644 test/files/neg/t7299.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 2458fc54e1..a98f20a971 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -4461,6 +4461,12 @@ trait Typers extends Modes with Adaptations with Tags { treeCopy.New(tree, tpt1).setType(tp) } + def functionTypeWildcard(tree: Tree, arity: Int): Type = { + val tp = functionType(List.fill(arity)(WildcardType), WildcardType) + if (tp == NoType) MaxFunctionArityError(tree) + tp + } + def typedEta(expr1: Tree): Tree = expr1.tpe match { case TypeRef(_, ByNameParamClass, _) => val expr2 = Function(List(), expr1) setPos expr1.pos @@ -4472,7 +4478,7 @@ trait Typers extends Modes with Adaptations with Tags { typed1(expr2, mode, pt) case PolyType(_, MethodType(formals, _)) => if (isFunctionType(pt)) expr1 - else adapt(expr1, mode, functionType(formals map (t => WildcardType), WildcardType)) + else adapt(expr1, mode, functionTypeWildcard(expr1, formals.length)) case MethodType(formals, _) => if (isFunctionType(pt)) expr1 else expr1 match { @@ -4491,7 +4497,7 @@ trait Typers extends Modes with Adaptations with Tags { val rhs = Apply(f, args) typed(rhs) case _ => - adapt(expr1, mode, functionType(formals map (t => WildcardType), WildcardType)) + adapt(expr1, mode, functionTypeWildcard(expr1, formals.length)) } case ErrorType => expr1 diff --git a/test/files/neg/t7299.check b/test/files/neg/t7299.check new file mode 100644 index 0000000000..74340c4841 --- /dev/null +++ b/test/files/neg/t7299.check @@ -0,0 +1,7 @@ +t7299.scala:4: error: implementation restricts functions to 22 parameters + val eta1 = f _ + ^ +t7299.scala:5: error: implementation restricts functions to 22 parameters + val eta2 = g[Any] _ + ^ +two errors found diff --git a/test/files/neg/t7299.scala b/test/files/neg/t7299.scala new file mode 100644 index 0000000000..f3aae5ce5d --- /dev/null +++ b/test/files/neg/t7299.scala @@ -0,0 +1,6 @@ +object Test { + def f(a1: Int, a2: Int, a3: Int, a4: Int, a5: Int, a6: Int, a7: Int, a8: Int, a9: Int, a10: Int, a11: Int, a12: Int, a13: Int, a14: Int, a15: Int, a16: Int, a17: Int, a18: Int, a19: Int, a20: Int, a21: Int, a22: Int, a23: Int) = 0 + def g[A](a1: Int, a2: Int, a3: Int, a4: Int, a5: Int, a6: Int, a7: Int, a8: Int, a9: Int, a10: Int, a11: Int, a12: Int, a13: Int, a14: Int, a15: Int, a16: Int, a17: Int, a18: Int, a19: Int, a20: Int, a21: Int, a22: Int, a23: Int) = 0 + val eta1 = f _ + val eta2 = g[Any] _ +} -- cgit v1.2.3