From 8b7eedfe394b9ae0d2395f5717ca6634e509b718 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Fri, 23 Sep 2022 08:38:28 -0700 Subject: [PATCH] Avoid warning on setter in trait The setter can be detected as isVar. Ignore its synthetic parameter. --- .../scala/tools/nsc/typechecker/TypeDiagnostics.scala | 2 +- test/files/pos/t12646.scala | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) create mode 100644 test/files/pos/t12646.scala diff --git a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala index ba79b1de5322..cc8655546ce7 100644 --- a/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala +++ b/src/compiler/scala/tools/nsc/typechecker/TypeDiagnostics.scala @@ -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 _ => diff --git a/test/files/pos/t12646.scala b/test/files/pos/t12646.scala new file mode 100644 index 000000000000..72118974d5fb --- /dev/null +++ b/test/files/pos/t12646.scala @@ -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 + } +}