File tree 3 files changed +55
-4
lines changed
compiler/src/dotty/tools/dotc/transform
tests/neg-custom-args/fatal-warnings
3 files changed +55
-4
lines changed Original file line number Diff line number Diff line change @@ -367,7 +367,7 @@ object CheckUnused:
367
367
explicitParamInScope += memDef
368
368
else if currScopeType.top == ScopeType .Local then
369
369
localDefInScope += memDef
370
- else if currScopeType.top == ScopeType . Template && memDef.symbol.is( Private , butNot = SelfName ) then
370
+ else if memDef.shouldReportPrivateDef then
371
371
privateDefInScope += memDef
372
372
373
373
/** Register pattern variable */
@@ -589,10 +589,13 @@ object CheckUnused:
589
589
590
590
private def isValidParam (using Context ): Boolean =
591
591
val sym = memDef.symbol
592
- (sym.is(Param ) || sym.isAllOf(PrivateParamAccessor )) &&
592
+ (sym.is(Param ) || sym.isAllOf(PrivateParamAccessor | Local , butNot = CaseAccessor )) &&
593
593
! isSyntheticMainParam(sym) &&
594
594
! sym.shouldNotReportParamOwner
595
595
596
+ private def shouldReportPrivateDef (using Context ): Boolean =
597
+ currScopeType.top == ScopeType .Template && ! memDef.symbol.isConstructor && memDef.symbol.is(Private , butNot = SelfName | Synthetic | CaseAccessor )
598
+
596
599
extension (imp : tpd.Import )
597
600
/** Enum generate an import for its cases (but outside them), which should be ignored */
598
601
def isGeneratedByEnum (using Context ): Boolean =
Original file line number Diff line number Diff line change @@ -17,4 +17,11 @@ class A:
17
17
18
18
val x = 1 // OK
19
19
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,45 @@ package foo.test.companionprivate:
73
73
74
74
object A :
75
75
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
+ }
You can’t perform that action at this time.
0 commit comments