Skip to content

Commit f5ea958

Browse files
committed
Fix #4600: method could be inside block in argument implicit resolution
1 parent f32aa36 commit f5ea958

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2250,6 +2250,12 @@ class Typer extends Namer
22502250
untpd.Apply(tree, args).withType(propFail)
22512251
}
22522252

2253+
// lifting may result in blocks, see tests/pos/i4600b.scala
2254+
def methSymbol: Symbol = tree match {
2255+
case Block(_, expr) => expr.symbol
2256+
case _ => tree.symbol
2257+
}
2258+
22532259
if (propFail.exists) {
22542260
// If there are several arguments, some arguments might already
22552261
// have influenced the context, binding variables, but later ones
@@ -2258,7 +2264,7 @@ class Typer extends Namer
22582264

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

tests/pos/i4600.scala

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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(): Unit = {
10+
new ImplicitExample().someMethod()
11+
}
12+
13+
def t2(): Unit = {
14+
implicit val s: String = "Hello"
15+
new ImplicitExample().someMethod()
16+
}
17+
18+
def t3(): Unit = {
19+
new ImplicitExample().run()
20+
}
21+
22+
def t4(): Unit = {
23+
implicit val s: String = "Hello"
24+
new ImplicitExample().run()
25+
}
26+
}

tests/pos/i4600b.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
class Foo(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") = ???
10+
11+
test(new Foo("port"))()
12+
}

0 commit comments

Comments
 (0)