Skip to content

Exporting an opaque type causes it to be seen as its underlying type #24051

@mrdziuban

Description

@mrdziuban

Compiler version

3.3.6, 3.4.3, 3.5.2, 3.6.4, 3.7.3, and latest nightly 3.8.0-RC1-bin-20250923-18f22ab-NIGHTLY

Minimized code

https://scastie.scala-lang.org/mrdziuban/VrghqzrKRLmn2DdndN75RQ/18

package example {
  package types {
    opaque type OpaqueType[A] = Unit
    object OpaqueType {
      def apply[A]: OpaqueType[A] = ()
    }
  }

  object exports {
    export example.types.OpaqueType
  }

  import exports.*

  def test[A](a: A)(using ev: A =:= Unit) = a

  val proof = test(OpaqueType[String])
}

Output

Successful compilation

Expectation

The call to test in val proof should not compile since OpaqueType[String] should not be seen as equivalent to Unit.

If the call is changed to test(types.OpaqueType[String]) then it does not compile, so the issue seems to be introduced by using the exported version of OpaqueType.

I believe this is related to #24014, #17220, and #17151

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions