Skip to content

Commit

Permalink
Ignore parameter of accessors, fixes #16955 (#16957)
Browse files Browse the repository at this point in the history
@szymon-rd Fixes #16955

- Do not report parameter of accessors
- Update test suit
  • Loading branch information
szymon-rd authored Feb 18, 2023
2 parents b67daed + d5fd114 commit f6c57d8
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 2 deletions.
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class CheckUnused extends MiniPhase:
ctx

override def prepareForIdent(tree: tpd.Ident)(using Context): Context =
if tree.symbol.exists then
if tree.symbol.exists then
unusedDataApply(_.registerUsed(tree.symbol, Some(tree.name)))
else if tree.hasType then
unusedDataApply(_.registerUsed(tree.tpe.classSymbol, Some(tree.name)))
Expand Down Expand Up @@ -621,7 +621,7 @@ object CheckUnused:
(sym.is(Param) || sym.isAllOf(PrivateParamAccessor | Local, butNot = CaseAccessor)) &&
!isSyntheticMainParam(sym) &&
!sym.shouldNotReportParamOwner &&
(!sym.exists || !sym.owner.isAllOf(Synthetic | PrivateLocal))
(!sym.exists || !(sym.owner.isAllOf(Synthetic | PrivateLocal) || sym.owner.is(Accessor)))

private def shouldReportPrivateDef(using Context): Boolean =
currScopeType.top == ScopeType.Template && !memDef.symbol.isConstructor && memDef.symbol.is(Private, butNot = SelfName | Synthetic | CaseAccessor)
Expand Down
3 changes: 3 additions & 0 deletions tests/neg-custom-args/fatal-warnings/i15503e.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,6 @@ package foo.test.trivial:
def f77(x: Int) = foo // error
}
object Y

package foo.test.i16955:
class S(var r: String) // OK
43 changes: 43 additions & 0 deletions tests/neg-custom-args/fatal-warnings/i15503i.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,49 @@ package foo.test.possibleclasses:
def a = k + y + s + t + z
}

package foo.test.possibleclasses.withvar:
case class AllCaseClass(
k: Int, // OK
private var y: Int // OK /* Kept as it can be taken from pattern */
)(
s: Int, // error /* But not these */
var t: Int, // OK
private var z: Int // error
)

case class AllCaseUsed(
k: Int, // OK
private var y: Int // OK
)(
s: Int, // OK
var t: Int, // OK
private var z: Int // OK
) {
def a = k + y + s + t + z
}

class AllClass(
k: Int, // error
private var y: Int // error
)(
s: Int, // error
var t: Int, // OK
private var z: Int // error
)

class AllUsed(
k: Int, // OK
private var y: Int // OK
)(
s: Int, // OK
var t: Int, // OK
private var z: Int // OK
) {
def a = k + y + s + t + z
}



package foo.test.from.i16675:
case class PositiveNumber private (i: Int) // OK
object PositiveNumber:
Expand Down

0 comments on commit f6c57d8

Please sign in to comment.