Skip to content

Fix #4600: method could be inside block in argument implicit resolution #4628

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
37 changes: 37 additions & 0 deletions tests/run/i4600.scala
Original file line number Diff line number Diff line change
@@ -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")
}
}
15 changes: 15 additions & 0 deletions tests/run/i4600b.scala
Original file line number Diff line number Diff line change
@@ -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")
}
}