Skip to content

Commit 20ebba5

Browse files
authored
Backport "Ignore parameter of accessors, fixes #16955" (#17270)
Backports #16957
2 parents ebba1cc + d4f8c74 commit 20ebba5

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

compiler/src/dotty/tools/dotc/transform/CheckUnused.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ object CheckUnused:
621621
(sym.is(Param) || sym.isAllOf(PrivateParamAccessor | Local, butNot = CaseAccessor)) &&
622622
!isSyntheticMainParam(sym) &&
623623
!sym.shouldNotReportParamOwner &&
624-
(!sym.exists || !sym.owner.isAllOf(Synthetic | PrivateLocal))
624+
(!sym.exists || !(sym.owner.isAllOf(Synthetic | PrivateLocal) || sym.owner.is(Accessor)))
625625

626626
private def shouldReportPrivateDef(using Context): Boolean =
627627
currScopeType.top == ScopeType.Template && !memDef.symbol.isConstructor && memDef.symbol.is(Private, butNot = SelfName | Synthetic | CaseAccessor)

tests/neg-custom-args/fatal-warnings/i15503e.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,6 @@ package foo.test.trivial:
5252
def f77(x: Int) = foo // error
5353
}
5454
object Y
55+
56+
package foo.test.i16955:
57+
class S(var r: String) // OK

tests/neg-custom-args/fatal-warnings/i15503i.scala

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,49 @@ package foo.test.possibleclasses:
126126
def a = k + y + s + t + z
127127
}
128128

129+
package foo.test.possibleclasses.withvar:
130+
case class AllCaseClass(
131+
k: Int, // OK
132+
private var y: Int // OK /* Kept as it can be taken from pattern */
133+
)(
134+
s: Int, // error /* But not these */
135+
var t: Int, // OK
136+
private var z: Int // error
137+
)
138+
139+
case class AllCaseUsed(
140+
k: Int, // OK
141+
private var y: Int // OK
142+
)(
143+
s: Int, // OK
144+
var t: Int, // OK
145+
private var z: Int // OK
146+
) {
147+
def a = k + y + s + t + z
148+
}
149+
150+
class AllClass(
151+
k: Int, // error
152+
private var y: Int // error
153+
)(
154+
s: Int, // error
155+
var t: Int, // OK
156+
private var z: Int // error
157+
)
158+
159+
class AllUsed(
160+
k: Int, // OK
161+
private var y: Int // OK
162+
)(
163+
s: Int, // OK
164+
var t: Int, // OK
165+
private var z: Int // OK
166+
) {
167+
def a = k + y + s + t + z
168+
}
169+
170+
171+
129172
package foo.test.from.i16675:
130173
case class PositiveNumber private (i: Int) // OK
131174
object PositiveNumber:

0 commit comments

Comments
 (0)