From ca77d84a8bb47fd6fd78151f734bd2d3874cd8a6 Mon Sep 17 00:00:00 2001 From: som-snytt Date: Fri, 28 Feb 2025 03:47:32 -0800 Subject: [PATCH] Regression test for extension nullification, nowarn for different opacities (#21191) Fixes #21190 ~Adjust~ test that params must not be of different opacity ~opaque~. ~Other aliases are permitted, but could check if they are effectively final. String alias can't be overridden.~ The tweak was https://github.com/scala/scala3/pull/22268 and the ticket was a duplicate. In the meantime, it also doesn't warn for any override, so the previous concern about aliases doesn't apply. [Cherry-picked ee62b32974eec926dc813b1d2d649a9e970ffa16] --- tests/warn/i21190.scala | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/warn/i21190.scala diff --git a/tests/warn/i21190.scala b/tests/warn/i21190.scala new file mode 100644 index 000000000000..652a4ad36853 --- /dev/null +++ b/tests/warn/i21190.scala @@ -0,0 +1,23 @@ + +//> using options -Werror + +opaque type FromEnd = Int +object FromEnd: + inline def apply(i: Int): FromEnd = i + extension (fe: FromEnd) + inline def value: Int = fe + +// Warning appears when extension is in same namespace as opaque type +extension [A](a: Array[A]) + inline def apply(fe: FromEnd): A = + a(a.length - 1 - FromEnd.value(fe)) + +class R: + def run(): String = + val xs = Array(1, 2, 3) + + s"""First element = ${xs(0)} + |Last element = ${xs(FromEnd(0))}""".stripMargin + +@main def test = println: + R().run()