Skip to content

Commit ca77d84

Browse files
som-snytttgodzik
authored andcommitted
Regression test for extension nullification, nowarn for different opacities (scala#21191)
Fixes scala#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 scala#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 ee62b32]
1 parent 3098364 commit ca77d84

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

tests/warn/i21190.scala

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
//> using options -Werror
3+
4+
opaque type FromEnd = Int
5+
object FromEnd:
6+
inline def apply(i: Int): FromEnd = i
7+
extension (fe: FromEnd)
8+
inline def value: Int = fe
9+
10+
// Warning appears when extension is in same namespace as opaque type
11+
extension [A](a: Array[A])
12+
inline def apply(fe: FromEnd): A =
13+
a(a.length - 1 - FromEnd.value(fe))
14+
15+
class R:
16+
def run(): String =
17+
val xs = Array(1, 2, 3)
18+
19+
s"""First element = ${xs(0)}
20+
|Last element = ${xs(FromEnd(0))}""".stripMargin
21+
22+
@main def test = println:
23+
R().run()

0 commit comments

Comments
 (0)