Use wildcard type instead of whitebox cast in IsoFields#1574
Merged
julien-truffaut merged 3 commits intoJul 13, 2026
Conversation
9c3c332 to
6f87f90
Compare
Member
|
Hi @mbovel, sorry for the delay. I missed this PR. Thanks for your doing it! would you mind adding the following?
case other => report.errorAndAbort(s"Unexpected mirror type: ${other.show}")
test("fields extension method works") {
case class Foo(s: String, i: Int)
val foo = Foo("hi", 5)
val iso: Iso[Foo, (String, Int)] = foo.focus.fields // or however the syntax works
assertEquals(iso.get(foo), ("hi", 5))
} |
6ca022e to
73c588b
Compare
Contributor
Author
|
Thanks @julien-truffaut. I addressed your comments in 73c588b. |
Member
|
Thanks @mbovel ! |
Contributor
Author
|
CI failed because of formatting; fixed, and rebased on top of main. |
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>
Address review comments: - Report a proper error message when the mirror expression doesn't match the expected shape in IsoFieldsImpl.apply - Add a test exercising the Iso.fields extension method on a value Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
8263797 to
9b87a44
Compare
julien-truffaut
approved these changes
Jul 13, 2026
julien-truffaut
added a commit
that referenced
this pull request
Jul 13, 2026
#1600) PR #1574 changed IsoFields.apply to return PIso[S, S, ? <: Tuple, ? <: Tuple] but GenIso._fields still fed the result into `whitebox`, which expects Expr[Iso[S, A]]. The wildcard type no longer unifies with Iso[S, A], breaking macrosJVM compilation on every Scala 3 JVM job (the CI page only showed temurin@25 red because fail-fast cancelled the others). Cast the IsoFields result directly to Expr[Iso[S, Any]] in the fallback branch, matching the erased cast `whitebox` already performs. Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mbovel
added a commit
to mbovel/Monocle
that referenced
this pull request
Jul 13, 2026
Declare the honest supertype PIso[S, S, ?, ?] instead, as optics-dev#1574 did for IsoFields. All match arms conform without a cast, and transparent inline still infers the precise type at call sites. This also fixes the master build, broken since optics-dev#1574. Co-Authored-By: Claude Fable 5 <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.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?