Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,18 @@ object desugar {
* def x: Int = expr
* def x_=($1: <TypeTree()>): Unit = ()
*
* Generate the setter only for non-private class members and all trait members.
* Generate the setter only for
* - non-private class members
* - all trait members
* - all package object members
*/
def valDef(vdef0: ValDef)(implicit ctx: Context): Tree = {
val vdef @ ValDef(name, tpt, rhs) = transformQuotedPatternName(vdef0)
val mods = vdef.mods
val setterNeeded =
mods.is(Mutable) && ctx.owner.isClass && (!mods.is(Private) || ctx.owner.is(Trait))
mods.is(Mutable)
&& ctx.owner.isClass
&& (!mods.is(Private) || ctx.owner.is(Trait) || ctx.owner.isPackageObject)
if (setterNeeded) {
// TODO: copy of vdef as getter needed?
// val getter = ValDef(mods, name, tpt, rhs) withPos vdef.pos?
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Namer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ class Namer { typer: Typer =>
val effectiveOwner = owner.skipWeakOwner
if (flags.is(Private) && effectiveOwner.is(Package)) {
// If effective owner is a package p, widen private to private[p]
flags1 = flags1 &~ Private
flags1 = flags1 &~ PrivateLocal
privateWithin = effectiveOwner
}

Expand Down
1 change: 1 addition & 0 deletions tests/pos/i7739.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
private var a: Int = 1