Skip to content

Use wildcard type instead of whitebox cast in IsoFields#1574

Draft
mbovel wants to merge 1 commit intooptics-dev:masterfrom
mbovel:fix-iso-fields-whitebox-type
Draft

Use wildcard type instead of whitebox cast in IsoFields#1574
mbovel wants to merge 1 commit intooptics-dev:masterfrom
mbovel:fix-iso-fields-whitebox-type

Conversation

@mbovel
Copy link
Copy Markdown

@mbovel mbovel commented Apr 11, 2026

Replace the whitebox cast (asInstanceOf[Expr[Iso[S, Tuple]]]) with a 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 (scala/scala3#25756). 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. Is that acceptable to use PIso instead of Iso?

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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant