Closed
Description
Minimized code
Only in the REPL, it seems like calling a chain of extension methods has a strange side effect that prevents it from happening again.
First, compile this source:
// IArr.scala
package example
import scala.reflect.ClassTag
object opaques:
opaque type IArr[+T] = Array[_ <: T]
given arrayOps: AnyRef with
extension [T](arr: IArr[T]) def reverse: IArr[T] =
genericArrayOps(arr).reverse
extension [T](arr: IArr[T]) def sorted(using math.Ordering[T]): IArr[T] =
genericArrayOps(arr).sorted
end opaques
type IArr[+T] = opaques.IArr[T]
object IArr:
inline def apply(inline x: Int, inline xs: Int*): IArr[Int] = Array(x, xs: _*).asInstanceOf
Then run the repl
task with IArr on the classpath
scala> import example.IArr
scala> IArr(1,2,3).reverse.sorted
val res0: example.opaques.IArr[Int] = Array(1, 2, 3)
scala> IArr(1,2,3).reverse.sorted
1 |IArr(1,2,3).reverse.sorted
|^^^^^^^^^^^^^^^^^^^^^^^^^^
|value sorted is not a member of example.opaques.IArr[Int].
|An extension method was tried, but could not be fully constructed:
|
| genericArrayOps[T](
| example.opaques.arrayOps.reverse[Int](example.IArr.apply(1, [2,3 : Int]*))
| )
scala>
Expectation
this is ok when they are called one after the other in a source file