Skip to content

fix #2163: don't narrow liftedOwner if symbol is InSuperCall #2216

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

Merged
merged 4 commits into from
Apr 11, 2017

Conversation

liufengyun
Copy link
Contributor

Fix #2163: don't narrow liftedOwner if symbol is InSuperCall

Previous, the algorithm narrows the lifted owner of anonymous functions in constructor calls to the class itself, lifted as a private method. However, if the anonymous function is called in super during initialization, JVM throws a uninitializedThis exception.

The fix additionally checks that narrowing only happens for symbols defined outside of super calls. As a result, the anonymous functions in constructor calls will be lifted as static methods, thus avoids the problem.

@liufengyun liufengyun requested a review from DarkDimius April 10, 2017 17:02
@odersky
Copy link
Contributor

odersky commented Apr 11, 2017

@liufengyun You correctly diagnosed the problem, but the fix is too radical. See the augmented test case, which generates illegal byte code with your fix. The correct place to put anonymous function is inside the Outer class, whereas with the initial patch it becomes a static function of the companion object. With the refined fix we should be good, I hope.

liufengyun and others added 4 commits April 11, 2017 14:11
The previous fix was too coarse. We need to move an anonymous function
in a supercall towards the call, we just have to make sure it's not
in the directly enclosing class.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Type uninitializedThis is not assignable
2 participants