From ddea9bbf7e79e6481da9a57206644d051e94fca5 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Mon, 24 Feb 2025 20:05:46 -0800 Subject: [PATCH] Nowarn non-private implicit val class params Dowarn protected param accessor of given, which was probably widened. [Cherry-picked 2cb2c9252b68abc66936705fa1496f736d338dbe] --- tests/warn/i15503f.scala | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/tests/warn/i15503f.scala b/tests/warn/i15503f.scala index 9d464bbc1973..79ee0a1767d4 100644 --- a/tests/warn/i15503f.scala +++ b/tests/warn/i15503f.scala @@ -43,3 +43,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