From bb7f2b8d98243c2d67ff1835fcfb1df5dbea9bb6 Mon Sep 17 00:00:00 2001 From: Eugene Burmako Date: Tue, 24 Feb 2015 16:25:06 +0100 Subject: better errors for macro applications with wrong number of arguments The tryNamesDefaults branch of application typechecking contains the checkNotMacro check, which errors out when we try to do named/default arguments for macros (that's not supported yet, see SI-5920 for discussion). Unfortunately, the check activates too early, because it turns out that we can also enter tryNamesDefaults when the user just provides insufficient number of arguments to a method by mistake, without expecting any default arguments at all. This leads to really confusing errors, which can luckily be fixed in a very simple way by moving the checkNotMacro check down the happy path of named/default typechecking. --- src/compiler/scala/tools/nsc/typechecker/Typers.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/compiler') diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 3a85d16f55..d4756f0af3 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -3387,7 +3387,6 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper // defaults are needed. they are added to the argument list in named style as // calls to the default getters. Example: // foo[Int](a)() ==> foo[Int](a)(b = foo$qual.foo$default$2[Int](a)) - checkNotMacro() // SI-8111 transformNamedApplication eagerly shuffles around the application to preserve // evaluation order. During this process, it calls `changeOwner` on symbols that @@ -3434,6 +3433,7 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper duplErrTree } else if (lencmp2 == 0) { // useful when a default doesn't match parameter type, e.g. def f[T](x:T="a"); f[Int]() + checkNotMacro() context.diagUsedDefaults = true doTypedApply(tree, if (blockIsEmpty) fun else fun1, allArgs, mode, pt) } else { -- cgit v1.2.3