Skip to content

Inlined method with return type "this.type" is ignored, when called several times #12829

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
edolgy opened this issue Jun 15, 2021 · 0 comments · Fixed by #12842
Closed

Inlined method with return type "this.type" is ignored, when called several times #12829

edolgy opened this issue Jun 15, 2021 · 0 comments · Fixed by #12842
Assignees
Milestone

Comments

@edolgy
Copy link

edolgy commented Jun 15, 2021

Compiler version

3.0.0

Minimized code

object Test:

  class Foo:
    var buf = ""

    def add(v: String): Unit = buf += v

    @scala.annotation.targetName("addOp") inline def += (inline v: String): this.type = {add(v); this }


  def main(sa: Array[String]): Unit =

    var fooVar = new Foo
    fooVar += "a" += "b" += "c"
    println(fooVar.buf)              // Prints: abc

    val fooVal = new Foo
    fooVal += "a" += "b" += "c"
    println(fooVal.buf)              // Prints: c     // Expected abc

Problem

If inlined method "+=" return type changed from "this.type" to Foo, the problem goes away.

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