Skip to content

Regression: lambdas capture this when they should not #1280

Closed
@DarkDimius

Description

@DarkDimius
  class LeakMe {
    def bar(a: Int => Int) = a(2)

    val s = 1
    def noCapture =       bar{x => println(x); x}
    def yesCapture =     bar{x => println(x + s); x}
  }

In this class, the lambda inside noCapture does not need the LeakMe instance and can be made a static method. It is made into a private method instead, implicitly capturing LeakMe.this

Unlike this, in scalac-2.11 the anonymous class created for noCapture does not capture LeakMe.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions