Skip to content

Nowarn public implicit val class params #22664

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
Mar 6, 2025
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
5 changes: 4 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/CheckUnused.scala
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,10 @@ object CheckUnused:
val alias = m.owner.info.member(sym.name)
if alias.exists then
val aliasSym = alias.symbol
if aliasSym.is(ParamAccessor) && !infos.refs(alias.symbol) then
val checking =
aliasSym.isAllOf(PrivateParamAccessor, butNot = CaseAccessor)
|| aliasSym.isAllOf(Protected | ParamAccessor, butNot = CaseAccessor) && m.owner.is(Given)
if checking && !infos.refs(alias.symbol) then
warnAt(pos)(UnusedSymbol.implicitParams)
else
warnAt(pos)(UnusedSymbol.implicitParams)
Expand Down
32 changes: 32 additions & 0 deletions tests/warn/i15503f.scala
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,35 @@ object Unmatched:
case Ident(name) =>
case _ =>
e

trait Ctx
case class K(i: Int)(using val ctx: Ctx) // nowarn
class L(val i: Int)(using val ctx: Ctx) // nowarn
class M(val i: Int)(using ctx: Ctx) // warn

package givens:

trait X:
def doX: Int

trait Y:
def doY: String

given X:
def doX = 7

given X => Y: // warn protected param to given class
def doY = "7"
/* desugared. It is protected so that its type can be used in member defs without leaking.
* possibly it should be protected only for named parameters.
given class given_Y(using x$1: givens.X) extends Object(), givens.Y {
protected given val x$1: givens.X
def doY: String = "7"
}
final given def given_Y(using x$1: givens.X): givens.given_Y =
new givens.given_Y(using x$1)()
*/

given namely: (x: X) => Y: // warn protected param to given class
def doY = "8"
end givens
Loading