Skip to content

Backport "Ignore parameter of accessors, fixes #16955" #17270

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
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