Skip to content

Commit 1056ac8

Browse files
committed
Make private type members Local if accessed only from this
1 parent f2edc11 commit 1056ac8

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,7 @@ object SymDenotations {
795795
* @param superAccess Access is via super
796796
* Everything is accessible if `pre` is `NoPrefix`.
797797
* A symbol with type `NoType` is not accessible for any other prefix.
798-
*
798+
*
799799
* As a side effect, drop Local flags of members that are not accessed via the ThisType
800800
* of their owner.
801801
*/
@@ -2192,19 +2192,16 @@ object SymDenotations {
21922192
validFor = Period.allInRun(NoRunId)
21932193
}
21942194

2195-
/** Can a pruvate symbol with given name and flags be inferred to be local,
2195+
/** Can a private symbol with given name and flags be inferred to be local,
21962196
* if all references to such symbols are via `this`?
2197-
* This holds for all term symbols, except
2197+
* This holds for all symbols except
21982198
* - constructors, since they can never be referred to as members of their
21992199
* own, fully elaborated `this`.
22002200
* - parameters and parameter accessors, since their Local status is already
22012201
* determined by whether they have a `val` or `var` or not.
22022202
*/
22032203
def canBeLocal(name: Name, flags: FlagSet)(given Context) =
2204-
name.isTermName
2205-
&& !name.isConstructorName
2206-
&& !flags.is(Param)
2207-
&& !flags.is(ParamAccessor)
2204+
!name.isConstructorName && !flags.is(Param) && !flags.is(ParamAccessor)
22082205

22092206
// ---- Completion --------------------------------------------------------
22102207

compiler/src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ class Namer { typer: Typer =>
288288
case _ => (flags.isTermFlags, flags.toTermFlags, "value")
289289
}
290290
def canBeLocal = tree match
291-
case tree: ValOrDefDef => SymDenotations.canBeLocal(tree.name, flags)
291+
case tree: MemberDef => SymDenotations.canBeLocal(tree.name, flags)
292292
case _ => false
293293
if !ok then
294294
ctx.error(i"modifier(s) `${flags.flagsString}` incompatible with $kind definition", tree.sourcePos)

0 commit comments

Comments
 (0)