Skip to content

Fix GenIso.fields compilation after IsoFields wildcard change#1601

Closed
mbovel wants to merge 1 commit into
optics-dev:masterfrom
mbovel:fix-geniso-wildcard-fallback
Closed

Fix GenIso.fields compilation after IsoFields wildcard change#1601
mbovel wants to merge 1 commit into
optics-dev:masterfrom
mbovel:fix-geniso-wildcard-fallback

Conversation

@mbovel

@mbovel mbovel commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Summary

CI on master is failing since #1574 with:

[E007] Type Mismatch Error: macro/src/main/scala-3/monocle/macros/GenIso.scala:77:49
77 |        whitebox('{ monocle.internal.IsoFields[S](using $e) })
   |          Found:    monocle.PIso[S, S, ? <: Tuple, ? <: Tuple]
   |          Required: monocle.Iso[S, A]

#1574 changed IsoFields.apply to return PIso[S, S, ? <: Tuple, ? <: Tuple], but the fallback arm of GenIso._fields passes that expression to whitebox[A](e: Expr[Iso[S, A]]), and the wildcard type cannot unify with Iso[S, A] (which requires both type parameters to be the same A).

Fix

Widen whitebox to accept Expr[PIso[S, S, ?, ?]]. All three match arms conform to it (Expr is covariant and Iso[S, A] = PIso[S, S, A, A]), and the cast it performs is unchanged. Since GenIso.fields is transparent inline, the precise type is still inferred at call sites.

Verification

  • sbt '++ 3' macrosJVM/test: compiles, 130/130 tests pass, including GenIso.fields on a two-field case class which exercises the fixed fallback arm.
  • sbt '++ 3' macrosJVM/scalafmtCheck: passes.

🤖 Generated with Claude Code

PR optics-dev#1574 changed IsoFields.apply to return
PIso[S, S, ? <: Tuple, ? <: Tuple], but the fallback arm of
GenIso._fields passes that expression to whitebox[A](e: Expr[Iso[S, A]]),
and the wildcard type cannot unify with Iso[S, A]. Widen whitebox to
accept Expr[PIso[S, S, ?, ?]], which all three match arms conform to;
the cast it performs is unchanged.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@mbovel

mbovel commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

This fix is the minimal change; but I think we can do better and instead completely remove whitebox usage, like in #1574. Here as well, whitebox lies: Iso[S, Unit] is not a subtype of Iso[S, Any]. I am working on it.

@mbovel

mbovel commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

Closing in favor of #1602.

@mbovel mbovel closed this Jul 13, 2026
@mbovel mbovel deleted the fix-geniso-wildcard-fallback branch July 13, 2026 16:51
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