-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand private members if necessary #517
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
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
661068a
Drop reference to NotJavaPrivate in access checks.
odersky d5df72a
New method for SymDenotations: ensureNotPrivate
odersky a263b5f
Make sure mixin accessors are not private.
odersky d9c2157
New miniphase: ExpandPrivate
odersky 55c7232
Get rid of NotPrivate flag.
odersky 592f2d5
Expand name should use initial owner.
odersky c01413e
Fixed doc comment.
odersky c69075a
ExpandPrivate: Make sure Deferred members are not Private.
DarkDimius 24e20af
SuperAccessors: Do not create abstract private members.
DarkDimius a0f5c20
TreeChecker: check for absence of private abstract methods.
DarkDimius 6ad6ca7
Refchecks runs before resolveSuper: superAccessors not yet materialised.
DarkDimius File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package dotty.tools.dotc | ||
package transform | ||
|
||
import core._ | ||
import DenotTransformers.IdentityDenotTransformer | ||
import Contexts.Context | ||
import Symbols._ | ||
import Scopes._ | ||
import Flags._ | ||
import StdNames._ | ||
import SymDenotations._ | ||
import Types._ | ||
import collection.mutable | ||
import TreeTransforms._ | ||
import Decorators._ | ||
import ast.Trees._ | ||
import TreeTransforms._ | ||
|
||
/** Makes private methods static, provided they not deferred, accessors, or static, | ||
* by rewriting a method `m` in class `C` as follows: | ||
* | ||
* private def m(ps) = e | ||
* | ||
* --> private static def($this: C, ps) = [this -> $this] e | ||
*/ | ||
class ExpandPrivate extends MiniPhaseTransform with IdentityDenotTransformer { thisTransform => | ||
import ast.tpd._ | ||
|
||
override def phaseName: String = "expandPrivate" | ||
|
||
/** Make private terms accessed from different classes non-private. | ||
* Note: this happens also for accesses between class and linked module class. | ||
* If we change the scheme at one point to make static module class computations | ||
* static members of the companion class, we should tighten the condition below. | ||
*/ | ||
private def ensurePrivateAccessible(d: SymDenotation)(implicit ctx: Context) = | ||
if (d.is(PrivateTerm) && d.owner != ctx.owner.enclosingClass) | ||
d.ensureNotPrivate.installAfter(thisTransform) | ||
|
||
override def transformIdent(tree: Ident)(implicit ctx: Context, info: TransformerInfo) = { | ||
ensurePrivateAccessible(tree.symbol) | ||
tree | ||
} | ||
|
||
override def transformSelect(tree: Select)(implicit ctx: Context, info: TransformerInfo) = { | ||
ensurePrivateAccessible(tree.symbol) | ||
tree | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,4 +6,8 @@ trait Test { | |
|
||
private def bar() = foo() | ||
|
||
class Inner { | ||
foo() | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This description was copy-pasted from
PrivateToStatic
and does not match what this phase does.