Skip to content

Unnecessary lifting of the receiver of a call to a method with varargs #5191

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
allanrenucci opened this issue Oct 2, 2018 · 1 comment
Closed

Comments

@allanrenucci
Copy link
Contributor

object Test {
  implicit class SCOps(ctx: StringContext) {
    def foo(args: String*): String = ""
  }

  def test(sc: StringContext, name: String) = {
    // {
    //   val $1$: Test.SCOps = Test.SCOps(sc)
    //   $1$.foo([ : String]: String*)
    // }
    sc.foo()

    // Test.SCOps(sc).foo([name : String]: String*)
    sc.foo(name)
  }
}
@allanrenucci
Copy link
Contributor Author

Actually it happens not only for implicit conversions but every-time the receiver cannot be proven pure:

class Test {
  def foo(args: String*): String = ""

  def test = {
    def self = this
    // {
    //   val $1$: Test = self
    //   $1$.foo([ : String]: String*)
    // }
    self.foo()

    // self.foo(["Hello" : String]: String*)
    self.foo("Hello")
  }
}

@allanrenucci allanrenucci changed the title Unnecessary lifting of implicit conversion for extension method with varargs Unnecessary lifting of the receiver of a call to a method with varargs Oct 2, 2018
allanrenucci added a commit to dotty-staging/dotty that referenced this issue Oct 2, 2018
…rargs

The receiver of a function is lifted if the call use default arguments.
To figure out if a default argument is needed, we compare the number of
passed arguments to the expected number of arguments.

Repeated arguments do not count as required arguments
allanrenucci added a commit that referenced this issue Oct 2, 2018
Fix #5191: Don't lift the receiver of a call to a method with varargs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant