Skip to content

Nested methods capture outer instance when lifted #9390

Description

@scabug

In this unit test, methodLift fails, while asFunction passes.

@Test
def methodLift {
    def isPrime(c: Int) = BigInt(c).isProbablePrime(1)
  assertNoOuter(isPrime)
}
@Test
def asFunction {
  val isPrime = (c: Int) => BigInt(c).isProbablePrime(1)
  assertNoOuter(isPrime)
}
private def assertNoOuter(f: Int => Boolean) {
  assertFalse(f.getClass.getDeclaredFields.exists(_.getType == this.getClass))
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions