From f6a4d945698bac9b64a2d2ddaf44eb7302336670 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Mon, 21 May 2012 11:41:23 -0700 Subject: SI-3761: Overload resolution fails on by-name parameter When isAsSpecific checks if method m applies to args of types of formal params of m1, a by-name parameter was converted to its underlying result type for the params (of m) but not the args (of m1). This had the useful effect of making m(A) more specific than m(=>A), which is the specified prioritization for implicit views, but also made m(=>A) and m(=>A, B*) ambiguous. To handle this edge case, the isCompatible test for A and =>A is made explicit, and by-name params are no longer converted. --- test/files/run/t3761-overload-byname.check | 4 ++++ test/files/run/t3761-overload-byname.scala | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 test/files/run/t3761-overload-byname.check create mode 100644 test/files/run/t3761-overload-byname.scala (limited to 'test') diff --git a/test/files/run/t3761-overload-byname.check b/test/files/run/t3761-overload-byname.check new file mode 100644 index 0000000000..9410a4fe65 --- /dev/null +++ b/test/files/run/t3761-overload-byname.check @@ -0,0 +1,4 @@ +hello! +hello working world +goodnight! +goodnight moon, nobody, noises everywhere diff --git a/test/files/run/t3761-overload-byname.scala b/test/files/run/t3761-overload-byname.scala new file mode 100644 index 0000000000..0e2c9b1059 --- /dev/null +++ b/test/files/run/t3761-overload-byname.scala @@ -0,0 +1,18 @@ + +class OverTheTop { + def info0(m: String) = m + "!" + def info0(m: String, args: Any*) = m +" "+ args.mkString(" ") + + // as reported + def info1(m: =>String) = m + "!" + def info1(m: =>String, args: Any*) = m +" "+ args.mkString(", ") +} +object Test { + def main(args: Array[String]) { + val top = new OverTheTop + println(top.info0("hello")) + println(top.info0("hello","working","world")) + println(top.info1("goodnight")) + println(top.info1("goodnight", "moon", "nobody", "noises everywhere")) + } +} -- cgit v1.2.3 From 8de2caa560d2c820269fd30207fdd22dd7e48c6b Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Tue, 22 May 2012 01:42:50 -0700 Subject: SI-3761: Overload resolution fails on by-name parameter (amended per lrytz) Lukas noted the stopgap at methTypeArgs isn't needed. What! No black tie formals. --- src/compiler/scala/tools/nsc/typechecker/Infer.scala | 3 +-- test/files/run/t3761-overload-byname.check | 2 ++ test/files/run/t3761-overload-byname.scala | 5 +++++ 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 34b951a797..f902198dda 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -694,8 +694,7 @@ trait Infer { isCompatibleArgs(argtpes, formals) && isWeaklyCompatible(restpe, pt) } else { try { - val blackTie = formalTypes(params map { _.tpe }, argtpes0.length) - val AdjustedTypeArgs.Undets(okparams, okargs, leftUndet) = methTypeArgs(undetparams, blackTie, restpe, argtpes, pt) + val AdjustedTypeArgs.Undets(okparams, okargs, leftUndet) = methTypeArgs(undetparams, formals, restpe, argtpes, pt) // #2665: must use weak conformance, not regular one (follow the monomorphic case above) (exprTypeArgs(leftUndet, restpe.instantiateTypeParams(okparams, okargs), pt, useWeaklyCompatible = true)._1 ne null) && isWithinBounds(NoPrefix, NoSymbol, okparams, okargs) diff --git a/test/files/run/t3761-overload-byname.check b/test/files/run/t3761-overload-byname.check index 9410a4fe65..3a0a273e64 100644 --- a/test/files/run/t3761-overload-byname.check +++ b/test/files/run/t3761-overload-byname.check @@ -2,3 +2,5 @@ hello! hello working world goodnight! goodnight moon, nobody, noises everywhere +0 +1 diff --git a/test/files/run/t3761-overload-byname.scala b/test/files/run/t3761-overload-byname.scala index 0e2c9b1059..b1656c97ba 100644 --- a/test/files/run/t3761-overload-byname.scala +++ b/test/files/run/t3761-overload-byname.scala @@ -6,6 +6,9 @@ class OverTheTop { // as reported def info1(m: =>String) = m + "!" def info1(m: =>String, args: Any*) = m +" "+ args.mkString(", ") + + // @lrytz + def m[A](x: => Int) = 0; def m[A](x: => Int, xs: Int*) = 1 } object Test { def main(args: Array[String]) { @@ -14,5 +17,7 @@ object Test { println(top.info0("hello","working","world")) println(top.info1("goodnight")) println(top.info1("goodnight", "moon", "nobody", "noises everywhere")) + println(top.m(17)) + println(top.m(17,19)) } } -- cgit v1.2.3