File tree Expand file tree Collapse file tree 3 files changed +61
-4
lines changed
compiler/src/dotty/tools/dotc/transform
tests/neg-custom-args/fatal-warnings Expand file tree Collapse file tree 3 files changed +61
-4
lines changed Original file line number Diff line number Diff line change @@ -367,7 +367,7 @@ object CheckUnused:
367367 explicitParamInScope += memDef
368368 else if currScopeType.top == ScopeType .Local then
369369 localDefInScope += memDef
370- else if currScopeType.top == ScopeType . Template && memDef.symbol.is( Private , butNot = SelfName ) then
370+ else if memDef.shouldReportPrivateDef then
371371 privateDefInScope += memDef
372372
373373 /** Register pattern variable */
@@ -589,10 +589,13 @@ object CheckUnused:
589589
590590 private def isValidParam (using Context ): Boolean =
591591 val sym = memDef.symbol
592- (sym.is(Param ) || sym.isAllOf(PrivateParamAccessor )) &&
592+ (sym.is(Param ) || sym.isAllOf(PrivateParamAccessor | Local , butNot = CaseAccessor )) &&
593593 ! isSyntheticMainParam(sym) &&
594594 ! sym.shouldNotReportParamOwner
595595
596+ private def shouldReportPrivateDef (using Context ): Boolean =
597+ currScopeType.top == ScopeType .Template && ! memDef.symbol.isConstructor && memDef.symbol.is(Private , butNot = SelfName | Synthetic | CaseAccessor )
598+
596599 extension (imp : tpd.Import )
597600 /** Enum generate an import for its cases (but outside them), which should be ignored */
598601 def isGeneratedByEnum (using Context ): Boolean =
Original file line number Diff line number Diff line change @@ -17,4 +17,11 @@ class A:
1717
1818 val x = 1 // OK
1919 def y = 2 // OK
20- def z = g // OK
20+ def z = g // OK
21+
22+ package foo .test .contructors:
23+ case class A private (x: Int ) // OK
24+ class B private (val x : Int ) // OK
25+ class C private (private val x : Int ) // error
26+ class D private (private val x : Int ): // OK
27+ def y = x
Original file line number Diff line number Diff line change @@ -73,4 +73,51 @@ package foo.test.companionprivate:
7373
7474 object A :
7575 private def b = c // OK
76- def c = List (1 ,2 ,3 ) // OK
76+ def c = List (1 ,2 ,3 ) // OK
77+
78+ package foo .test .possibleclasses:
79+ case class AllCaseClass (
80+ k : Int , // OK
81+ private val y : Int // OK /* Kept as it can be taken from pattern */
82+ )(
83+ s : Int , // error /* But not these */
84+ val t : Int , // OK
85+ private val z : Int // error
86+ )
87+
88+ case class AllCaseUsed (
89+ k : Int , // OK
90+ private val y : Int // OK
91+ )(
92+ s : Int , // OK
93+ val t : Int , // OK
94+ private val z : Int // OK
95+ ) {
96+ def a = k + y + s + t + z
97+ }
98+
99+ class AllClass (
100+ k : Int , // error
101+ private val y : Int // error
102+ )(
103+ s : Int , // error
104+ val t : Int , // OK
105+ private val z : Int // error
106+ )
107+
108+ class AllUsed (
109+ k : Int , // OK
110+ private val y : Int // OK
111+ )(
112+ s : Int , // OK
113+ val t : Int , // OK
114+ private val z : Int // OK
115+ ) {
116+ def a = k + y + s + t + z
117+ }
118+
119+ package foo .test .from .i16675:
120+ case class PositiveNumber private (i : Int ) // OK
121+ object PositiveNumber :
122+ def make (i : Int ): Option [PositiveNumber ] = // OK
123+ Option .when(i >= 0 )(PositiveNumber (i)) // OK
You can’t perform that action at this time.
0 commit comments