Use wildcard type instead of whitebox cast in IsoFields#1574
Draft
mbovel wants to merge 1 commit intooptics-dev:masterfrom
Draft
Use wildcard type instead of whitebox cast in IsoFields#1574mbovel wants to merge 1 commit intooptics-dev:masterfrom
mbovel wants to merge 1 commit intooptics-dev:masterfrom
Conversation
Replace the `whitebox` cast (`asInstanceOf[Expr[Iso[S, Tuple]]]`) with a proper wildcard return type using `PIso[S, S, ? <: Tuple, ? <: Tuple]`. Since `IsoFields.apply` is a `transparent inline` method, the compiler still infers the precise tuple type at call sites. This avoids the unsafe cast and prepares for potential stricter macro type checking in future Scala versions. The motivation is to prepare for future stricter checks in the Scala 3 compiler. The current implementation exploits a missing check to generate an unsound cast. Note: we use `PIso` (a trait) directly instead of the `Iso` type alias (defined as `type Iso[S, A] = PIso[S, S, A, A]`) because Scala 3 cannot reduce higher-kinded type aliases applied to wildcard arguments. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replace the
whiteboxcast (asInstanceOf[Expr[Iso[S, Tuple]]]) with a wildcard return type usingPIso[S, S, ? <: Tuple, ? <: Tuple].Since
IsoFields.applyis atransparent inlinemethod, the compiler still infers the precise tuple type at call sites. This avoids the unsafe cast and prepares for potential stricter macro type checking in future Scala versions.The motivation is to prepare for future stricter checks in the Scala 3 compiler (scala/scala3#25756). The current implementation exploits a missing check to generate an unsound cast.
Note: we use
PIso(a trait) directly instead of theIsotype alias (defined astype Iso[S, A] = PIso[S, S, A, A]) because Scala 3 cannot reduce higher-kinded type aliases applied to wildcard arguments. Is that acceptable to usePIsoinstead ofIso?