-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Safe initialization for Scala #7789
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
Conversation
51e0898
to
af9c2bc
Compare
Cool stack trace, how about :
would be better to provide a screenshot |
It should be better to provide some helpful information for how to fix it like what unison does. |
e343407
to
7b2a90b
Compare
This seems quite restrictive. There are libraries that use anonymous classes as a scope injection mechanism. I imagine something like the following be rejected, if the extended type is from another project: foo(new {
enter(1, "one")
enter(2, "two")
}) |
foo(new {
enter(1, "one")
enter(2, "two")
}) The code above per se is not an issue, the checker can statically know that no fields in the child class may be reached --- as there is no overriding & local field access. It may relax the rule in such cases. |
a6578f8
to
185ec56
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from a few opportunities for DRY-ing the code, looks very good to me. The code is easy to follow and the architecture is clear, nice work!
compiler/src/dotty/tools/dotc/transform/init/CheckingPhase.scala
Outdated
Show resolved
Hide resolved
compiler/src/dotty/tools/dotc/transform/init/Summarization.scala
Outdated
Show resolved
Hide resolved
7403b66
to
d90f14e
Compare
Is there a tracking issue interested parties could subscribe to for this feature? |
There is a contributor thread: https://contributors.scala-lang.org/t/improve-forward-reference-handling/3616/9 |
Thanks. I was hoping a GitHub issue, as issues have state (open/closed) and also one can subscribe to solely the closing of the issue. Discourse threads, much like Google Docs, have no such known state. (Just sharing thoughts, so you can consider them.) |
@dwijnand Thanks for the detailed explanation: it's possible to subscribe to this PR, and get notified when it's merged (on the right-hand side of the page). |
a09993d
to
22d853d
Compare
@anatoliykmetyuk : I have run the check on the whole test set (and community projects), all crashes are fixed. Could you have a look at the latest changes? |
56205ad
to
33b3d25
Compare
ErasedFunctionX does not have constructors, thus no need to follow. dotc -d out -Yerased-terms -Ycheck-init tests/run-custom-args/erased/erased-15.scala
dotc -d out -Ycheck-init tests/run/vc-equals.scala
dotc -d out -Ycheck-init tests/pos/aliasNew.scala
The method name is not an invariant: dotc -d out -Ycheck-init tests/pos/i4350.scala
dotc -d out -Ycheck-init tests/pos/SI-4012-b.scala
dotc -d out -Ycheck-init tests/run/polymorphic-functions.scala
dotc -d out -Ycheck-init tests/pos/annot.scala
It should return a tuple of effects and potentials due to length limit. Previously, the effects are checked but the errors are thrown away.
97d4b22
to
1694e4a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, nice work @liufengyun 🎉
@anatoliykmetyuk Thanks a lot for your valuable feedback in the review. |
This PR implements experimental safe initialization check for Scala, which can be enabled by the compiler option
-Ycheck-init
.A Quick Glance
Parent-Child Interaction
Given the following code snippet:
The checker will report:
Inner-Outer Interaction
Given the code below:
The checker will report:
Functions
Given the code below:
The checker reports:
More details about the design can be found in the document or gist.
This PR is based on a series of joint work with Ondřej Lhoták (@olhotak), Aggelos Biboudis (@biboudis) and Paolo G. Giarrusso (@Blaisorblade).