Which reflection-based frameworks bypass compile-time type checks for Scala 3 opaque type aliases?
0 reputation · 18 Jul 2025, 13:04 UTC
Scala 3 opaque type aliases are designed to enforce compile-time type abstraction by erasing to their underlying representation. However, the degree to which reflection-driven frameworks can inspect or reconstruct these types outside their defining scope remains an open design question. This goal focuses on mapping the boundary conditions where the intended abstraction barrier weakens under reflective inspection.
Constraints involve the Scala 3 compiler's erasure semantics, the lexical scope of the opaque type definition, and the capabilities of common reflection APIs such as runtime mirroring and class tag derivation. When opaque types are exposed through library interfaces consumed by frameworks that bypass compile-time checks, the abstraction may dissolve, potentially enabling unintended type coercion or runtime failures.
Which reflection-based mechanisms can access the underlying type of a Scala 3 opaque alias outside its defining scope? Does the Java reflection layer preserve the opaque type's identity, or does it always resolve to the erased base type? What safeguards, if any, can library authors employ to mitigate accidental exposure without sacrificing interoperability?