Skip to content

transparent inline leak underlying opaque types #13461

@soronpo

Description

@soronpo

The transparent inline macro that exists within an opaque source can leak the underlying opaque type.
Note that this does not occur if the macro is not transparent, or if the inline is not a macro.
Additionally, we require another pass through a transparent leak definition to expose this leak (in this example it is implemented with given ... with, but that could be a transparent inline that does the same thing).

Compiler version

v3.1.0-RC1

Minimized code

Minimized project at: https://github.com/soronpo/dottybug/tree/transparent_opaque_leak

MyOpaque.scala

import scala.quoted.*
opaque type MyOpaque = Int
object MyOpaque:
  val one: MyOpaque = 1
  transparent inline def apply(): MyOpaque = ${ applyMacro }
  private def applyMacro(using Quotes): Expr[MyOpaque] =
    import quotes.reflect.*
    '{ one }

Leak.scala

trait Leak[T]:
  type Out
given [T]: Leak[T] with
  type Out = T
extension [T](t: T)(using l: Leak[T]) def leak: l.Out = ???

val x = MyOpaque().leak
val shouldWork = summon[x.type <:< MyOpaque]

Output

[error] 8 |val shouldWork = summon[x.type <:< MyOpaque]
[error]   |                                            ^
[error]   |               Cannot prove that (x : given_Leak_T[Int]#Out) <:< MyOpaque.
[error] one error found

Expectation

No error.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions