Skip to content

Commit 38f8bdd

Browse files
committed
Fix #4600: method could be inside block in argument implicit resolution
1 parent 9d92d85 commit 38f8bdd

File tree

3 files changed

+53
-1
lines changed

3 files changed

+53
-1
lines changed

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2258,7 +2258,7 @@ class Typer extends Namer
22582258

22592259
// If method has default params, fall back to regular application
22602260
// where all inferred implicits are passed as named args.
2261-
if (tree.symbol.hasDefaultParams && !propFail.isInstanceOf[AmbiguousImplicits]) {
2261+
if (methPart(tree).symbol.hasDefaultParams && !propFail.isInstanceOf[AmbiguousImplicits]) {
22622262
val namedArgs = (wtp.paramNames, args).zipped.flatMap { (pname, arg) =>
22632263
if (arg.tpe.isError) Nil else untpd.NamedArg(pname, untpd.TypedSplice(arg)) :: Nil
22642264
}

tests/run/i4600.scala

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import scala.language.dynamics
2+
3+
class ImplicitExample() extends Dynamic {
4+
def someMethod()(implicit s: String = "World"): String = s
5+
def applyDynamic(name: String)(args: Any*)(implicit s: String = "World"): String = name + s
6+
}
7+
8+
class ImplicitTest {
9+
def t1() = {
10+
new ImplicitExample().someMethod()
11+
}
12+
13+
def t2() = {
14+
implicit val s: String = "Hello"
15+
new ImplicitExample().someMethod()
16+
}
17+
18+
def t3() = {
19+
new ImplicitExample().run()
20+
}
21+
22+
def t4() = {
23+
implicit val s: String = "Hello"
24+
new ImplicitExample().run()
25+
}
26+
}
27+
28+
29+
object Test {
30+
def main(args: Array[String]) = {
31+
val it = new ImplicitTest
32+
assert(it.t1() == "World")
33+
assert(it.t2() == "Hello")
34+
assert(it.t3() == "runWorld")
35+
assert(it.t4() == "runHello")
36+
}
37+
}

tests/run/i4600b.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
class Foo(val config: String) {
2+
case class Bar(val x: Int) {
3+
def doThings: String = config //Do whatever here
4+
}
5+
}
6+
7+
8+
object Test {
9+
def test(foo: Foo)(bar: foo.Bar = foo.Bar(5))(implicit s: String = "ok") = s + foo.config + bar.x
10+
11+
def main(args: Array[String]) = {
12+
val res = test(new Foo("port"))()
13+
assert(res == "okport5")
14+
}
15+
}

0 commit comments

Comments
 (0)