Skip to content
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

Init: Promote this after all its fields have been initialized #11278

Merged
merged 5 commits into from
Feb 11, 2021

Conversation

natsukagami
Copy link
Contributor

@natsukagami natsukagami commented Feb 2, 2021

Description

The initialization checker will now accept uses of this and this-referencing objects as fully-initialized objects ("hot") after all val declarations have been evaluated.

Simple example:

class Obj() {
    val a = 1
    List(this) // Previously fails, now succeeds
}
    

A simple test is included.


This change is Reviewable

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @natsukagami. While you are on it, could you incorporate some of the improvements in #10627 (excluding promotion of warm), in this PR or a new one? It will make subsequent work easier.

class P() {
val a = 1
List(this)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to add a test that a warm inner class object promotes to hot because of the outer object being hot.

if (allFieldsInited)
Errors.empty
else
PromoteThis(pot, eff.source, state2.path).toErrors
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might be good to cache safely promoted potentials to avoid re-computation. See #10627.

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@liufengyun liufengyun merged commit cb47acd into scala:master Feb 11, 2021
@Kordyjan Kordyjan added this to the 3.0.0 milestone Aug 2, 2023
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.

None yet

3 participants