Skip to content

Commit

Permalink
Avoid warning on setter in trait
Browse files Browse the repository at this point in the history
The setter can be detected as isVar. Ignore its synthetic parameter.
  • Loading branch information
som-snytt committed Sep 23, 2022
1 parent 98972e5 commit 8b7eedf
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ trait TypeDiagnostics extends splain.SplainDiagnostics {
if (sym.isPrimaryConstructor)
for (cpa <- sym.owner.constrParamAccessors if cpa.isPrivateLocal) params += cpa
else if (sym.isSynthetic && sym.isImplicit) return
else if (!sym.isConstructor && !isTrivial(rhs))
else if (!sym.isConstructor && !sym.isVar && !isTrivial(rhs))
for (vs <- vparamss) params ++= vs.map(_.symbol)
defnTrees += m
case _ =>
Expand Down
11 changes: 11 additions & 0 deletions test/files/pos/t12646.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

// scalac: -Werror -Wunused:params

trait T {
private var x: String = _

def y: String = {
if (x eq null) x = "hello, world"
x
}
}

0 comments on commit 8b7eedf

Please sign in to comment.