Scala 3 Opaque Types: Type-Safe IDs Without Runtime Wrappers
Opaque types make UserId and OrderId distinct to the Scala 3 compiler while erasing to Long at runtime. Here's the pattern, what erasure costs, and how to verify both.
ReadMeFeed / Community knowledge
Real questions. Useful conversations. Find the people who know your stack.
Opaque types make UserId and OrderId distinct to the Scala 3 compiler while erasing to Long at runtime. Here's the pattern, what erasure costs, and how to verify both.
Make Scala 3 type class resolution explicit with given instances and using parameters. A task guide covering prerequisites, migration steps, checks and recovery for predictable imports.
Understanding implicit priority for Scala 3 using parameters when the bindings live in different source files. The using keyword introduces implicit parameters that are passed automatically, and resolution is described as nearest-scope first. The uncertainty is how nearest scope is defined across compilation units. When multiple using groups for the same typ
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
Symptom A Scala 3 method declares a context parameter with a using clause, and more than one eligible given instance is visible through local definitions, imports, or the implicit scope of the expected type. The compiler reports ambiguous implicit values instead of selecting one instance. Goal and constraints The goal is to diagnose which candidate givens th
Scala 3 introduces given and using to replace the overloaded implicit keyword, aiming to provide clearer intent for dependency injection and type class resolution. When defining type class instances, the compiler searches local scopes, imported scopes, and companion objects. Uncertainty arises when multiple given instances of the same type are available acro
A library that cross-builds for Scala 2.13 and Scala 3 needs a zero-cost wrapper for identifiers in a hot path, while keeping the public API distinct from the underlying type. Two documented options are Scala 3 opaque type aliases and value classes that extend AnyVal . Opaque types hide their representation outside the defining scope and are erased to the un
Goal Restore a project to a working Scala 2.13 state after a partially applied upgrade to Scala 3, without leaving mixed‑version artifacts that could corrupt future builds. Constraints Scala 3 compiles to TASTy files that embed a format version. The 2.13 compiler cannot consume TASTy produced by a newer compiler, so any leftover Scala 3 TASTy in the classpat
Goal: Preserve Implicit Behavior During Migration In a low‑traffic workload, the primary concern is to keep existing functionality intact while moving from Scala 2.13 to Scala 3. The language‑level change from implicit to given/using is documented as a source‑compatible transition, but the impact on implicit resolution, especially conversion chaining, is not