diff --git a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala index c441e43a7288..ade55138e15d 100644 --- a/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala +++ b/compiler/src/dotty/tools/dotc/transform/CheckUnused.scala @@ -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) diff --git a/tests/warn/i15503f.scala b/tests/warn/i15503f.scala index 0550f82d9398..e134c2ded422 100644 --- a/tests/warn/i15503f.scala +++ b/tests/warn/i15503f.scala @@ -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