scala/scala — pull request #576 by axel22 (2012-05-18 16:54:12+00:00)
Title: Issue/4717

Fixes SI-4717.
A lazy val declared inside an anonymous class inside a specialized
context no longer crashes Duplicators.

Previously, a duplicated lazy val was assigned to the wrong owner
in Duplicators:

class Foo[@specialized(Boolean) A] {
def x[B >: A]: Unit = new Bounds[B] {
lazy val it = ??? // def or val okay
}
}

Above, the `it` in `$anon` in `x$mcZ$sp` had its owner set to `x$mcZ$sp`
instead of `$anon`. This crashed the typer when it had to retype its
lazy accessor, because there was no `lazy var it` in `$anon`.
Furthermore, the duplicated symbol wasn't being added to the list of
declarations of `$anon`.

Changes:
1) `invalidate` in Duplicators takes an additional parameter which is
the new owner of the new symbol that has to be duplicated. If this parameter
is set to `NoSymbol`, then the new owner is `context.owner`, as before.
2) the newly created lazy val symbol is being added to the list of
declarations of its new owner, provided that the owner is a class.

Review by dragos.
@mention dragos
review by @dragos