From 38f8bdd0ade18d6017f47d5a0ff8b81ebf02a4fe Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Fri, 8 Jun 2018 14:56:28 +0200 Subject: [PATCH] Fix #4600: method could be inside block in argument implicit resolution --- .../src/dotty/tools/dotc/typer/Typer.scala | 2 +- tests/run/i4600.scala | 37 +++++++++++++++++++ tests/run/i4600b.scala | 15 ++++++++ 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 tests/run/i4600.scala create mode 100644 tests/run/i4600b.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 733ac8be3a41..049ec5d4b5ea 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -2258,7 +2258,7 @@ class Typer extends Namer // If method has default params, fall back to regular application // where all inferred implicits are passed as named args. - if (tree.symbol.hasDefaultParams && !propFail.isInstanceOf[AmbiguousImplicits]) { + if (methPart(tree).symbol.hasDefaultParams && !propFail.isInstanceOf[AmbiguousImplicits]) { val namedArgs = (wtp.paramNames, args).zipped.flatMap { (pname, arg) => if (arg.tpe.isError) Nil else untpd.NamedArg(pname, untpd.TypedSplice(arg)) :: Nil } diff --git a/tests/run/i4600.scala b/tests/run/i4600.scala new file mode 100644 index 000000000000..5909e23b6ec1 --- /dev/null +++ b/tests/run/i4600.scala @@ -0,0 +1,37 @@ +import scala.language.dynamics + +class ImplicitExample() extends Dynamic { + def someMethod()(implicit s: String = "World"): String = s + def applyDynamic(name: String)(args: Any*)(implicit s: String = "World"): String = name + s +} + +class ImplicitTest { + def t1() = { + new ImplicitExample().someMethod() + } + + def t2() = { + implicit val s: String = "Hello" + new ImplicitExample().someMethod() + } + + def t3() = { + new ImplicitExample().run() + } + + def t4() = { + implicit val s: String = "Hello" + new ImplicitExample().run() + } +} + + +object Test { + def main(args: Array[String]) = { + val it = new ImplicitTest + assert(it.t1() == "World") + assert(it.t2() == "Hello") + assert(it.t3() == "runWorld") + assert(it.t4() == "runHello") + } +} diff --git a/tests/run/i4600b.scala b/tests/run/i4600b.scala new file mode 100644 index 000000000000..545c0483e51e --- /dev/null +++ b/tests/run/i4600b.scala @@ -0,0 +1,15 @@ +class Foo(val config: String) { + case class Bar(val x: Int) { + def doThings: String = config //Do whatever here + } +} + + +object Test { + def test(foo: Foo)(bar: foo.Bar = foo.Bar(5))(implicit s: String = "ok") = s + foo.config + bar.x + + def main(args: Array[String]) = { + val res = test(new Foo("port"))() + assert(res == "okport5") + } +}