Skip to content

Fix #9664: check outer of warm values #9665

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 2 commits into from
Aug 28, 2020
Merged

Conversation

liufengyun
Copy link
Contributor

Fix #9664: check outer of warm values

Copy link
Member

@bishabosha bishabosha left a comment

Choose a reason for hiding this comment

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

this still makes the warning when A is defined by new anonymous class:

class Wrap3 {
  class E
  object E {
    final val A = new E {}
    val ref = Array(A)
  }
}

@liufengyun
Copy link
Contributor Author

liufengyun commented Aug 28, 2020

Leaking inner class instances could lead to errors:

class Wrap3 {
  def qux(e: E) = e.foo

  abstract class E { def foo: T }
  object E {
    final val A = new E { def foo = ref }
    val ref = qux(A)
  }
}

Generally, checking safe early promotion of inner class instances is expensive (it needs to go through all the code in its body and its parents), thus currently the checker deems such leaking as unsafe. However, improvements are envisioned to check small inner classes to improve usability.

@bishabosha
Copy link
Member

bishabosha commented Aug 28, 2020

ah I see that scala.runtime.EnumValues.register was previously added in Checker.ignoredMethods which would cover the $new method for enums, do you think that instead we could add Array.apply now that scala.runtime.EnumValues is no longer used?

@liufengyun
Copy link
Contributor Author

liufengyun commented Aug 28, 2020

ah I see that scala.runtime.EnumValues.register was previously added in Checker.ignoredMethods which would cover the $new method for enums, do you think that instead we could add Array.apply now that scala.runtime.EnumValues is no longer used?

Adding Array.apply as ignored opens a big door for unsafety. If such code is safe in the case of enums, you can use Array(A : @unchecked) to silence the checker.

@bishabosha
Copy link
Member

ah very cool, thanks

@bishabosha bishabosha self-requested a review August 28, 2020 13:49
Copy link
Member

@bishabosha bishabosha left a comment

Choose a reason for hiding this comment

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

LGTM

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.

-Ycheck-init promoting value to fully initialised when passed to array
3 participants