scala3
scala3 copied to clipboard
type "leakage" with transparent methods on opaque types
Compiler version
3.4.2-RC1
Minimized code
opaque type Repro = Int
object Repro:
extension(v: Int)
// lift raw Int
inline def asRepro: Repro = v
extension(r: Repro)
// this doesn't need to be transparent but my actual
// use case does
transparent inline def *(rr: Repro): Repro =
r * rr
object repro:
import Repro.asRepro
val x = 2.asRepro
// this "leaks" the type 'Int'
val y: (Repro & Int) = x * x
// this should fail but doesn't
val z = 1 + y
Output
The *
method returns type Repro & Int
, due to transparent
keyword. In other words, it leaks the implementation type Int
Expectation
I need a way for transparent methods to return only Repro
, not Repro & Int
, to prevent leaky abstraction of the opaque type.