Skip to content

Implicit Argument / vararg with Dynamic Trait fails #4600

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

Closed
max-leuthaeuser opened this issue May 30, 2018 · 2 comments · Fixed by #4628
Closed

Implicit Argument / vararg with Dynamic Trait fails #4600

max-leuthaeuser opened this issue May 30, 2018 · 2 comments · Fixed by #4628

Comments

@max-leuthaeuser
Copy link

Consider the following simple example:

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
}

And its test:

class ImplicitTest {
  @Test def t1(): Unit = {
    assertEquals("World", new ImplicitExample().someMethod())
  }

  @Test def t2(): Unit = {
    implicit val s: String = "Hello"
    assertEquals("Hello", new ImplicitExample().someMethod())
  }

  @Test def t3(): Unit = {
    assertEquals("runWorld", new ImplicitExample().run())
  }

  @Test def t4(): Unit = {
    implicit val s: String = "Hello"
    assertEquals("runHello", new ImplicitExample().run())
  }
}

Test t1 and t2 always work, while t3 fails with the latest Nightly build (0.9.0-bin-20180529-be6ae0e-NIGHTLY):

[error] -- Error: ... ImplicitTest.scala: ...
[error] 15 |    assertEquals("runWorld", new ImplicitExample().run())
[error]    |                                                      ^
[error]    |no implicit argument of type String was found for parameter s of method applyDynamic in class ImplicitExample
[error] one error found
[error] (Test / compileIncremental) Compilation failed

If you remove the vararg args, it compiles but the implicit parameter is not considered anymore and t4 fails with:

[error] Test ImplicitTest.t4 failed: expected:<run[Hello]> but was:<run[World]>

Everything is fine with 0.8.0-RC1.

@allanrenucci
Copy link
Contributor

Regression from #4428

@liufengyun
Copy link
Contributor

I'm pushing a fix soon, found a bug both in Dotty & Scalac:

class Foo(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") = ???

  test(new Foo("port"))()              // failed, should succeed!
}

liufengyun added a commit to dotty-staging/dotty that referenced this issue Jun 8, 2018
liufengyun added a commit to dotty-staging/dotty that referenced this issue Jun 8, 2018
allanrenucci added a commit that referenced this issue Jun 8, 2018
Fix #4600: method could be inside block in argument implicit resolution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants