Skip to content

fix(compiler): shape re"..." no longer warns W0012 on its own synthesized null - #1997

Merged
kmizu merged 1 commit into
developfrom
fix/shape-regex-synthesized-null-printer-warning
Oct 4, 2026
Merged

kmizu merged 1 commit into
developfrom
fix/shape-regex-synthesized-null-printer-warning

Conversation

@kmizu

@kmizu kmizu commented Oct 4, 2026

Copy link
Copy Markdown
Member

What

  • A shape name = re"..." clause whose pattern has no unique rendering (e.g. re"(-?\d+)\s+(-?\d+)") no longer emits [W0012] null assigned where non-nullable 'onion.Function1[R, String]' is expected on the shape clause -- a warning about a null the user never wrote.

Why

The synthesized read-only shape passed a literal null printer to Shapes::regex. W0012's null-to-non-nullable check is correct, by design, for user code that writes null into a non-nullable generic position (see NullToNonNullableSpec, NullToTypeVariableGenericSpec), but it should never fire on compiler-generated code the user has no control over. A new no-printer Shapes.regex overload lets the synthesized call skip the argument entirely instead of passing null through Onion's type checker.

Found while probing shape macros for gaps (every shape ... = re"..." declaration with a non-invertible pattern was affected).

Notes for reviewers

  • An earlier attempt fixed this by casting the synthesized null to the exact Function1[R, String] type instead of adding an overload. That cast broke overload resolution for Shapes::regex's generic T (a separate, pre-existing gap in generic-argument inference when an already-concretely-typed expression is passed at a type-variable position alongside a closure argument). The no-printer overload sidesteps that gap entirely rather than fixing it; the inference gap itself is not addressed here.

Verification

  • New regression test ShapeRegexNonInvertibleNoWarningSpec (red before the fix, green after).
  • Full suite: SBT_OPTS="-Xmx10G -XX:+UseG1GC -Xss16m" sbt -Duser.language=en testFull -- 8351 passed, 0 failed, 2 canceled (pre-existing, unrelated).

🤖 Generated with Claude Code

https://claude.ai/code/session_01S8s9sFYBxQuCjnkgmdRSde


Generated by Claude Code

…ized null

What:
- A `shape name = re"..."` clause whose pattern has no unique
  rendering (e.g. `re"(-?\d+)\s+(-?\d+)"`) no longer emits
  `[W0012] null assigned where non-nullable 'onion.Function1[...]'
  is expected` on the shape clause -- a warning about a `null` the
  user never wrote.

Why: the synthesized read-only shape passed a literal `null` printer
to `Shapes::regex`, which the W0012 null-to-non-nullable check (by
design, see NullToNonNullableSpec/NullToTypeVariableGenericSpec)
correctly flags for user code but should never see from compiler-
generated code. A new no-printer `Shapes.regex` overload lets the
synthesized call skip the argument instead of passing `null` through
Onion's type checker. Found while probing shape macros for gaps.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01S8s9sFYBxQuCjnkgmdRSde
Co-Authored-By: 音羽ここね <kokone.ai.main@gmail.com>
@kmizu
kmizu merged commit fc720de into develop Oct 4, 2026
3 checks passed
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.

2 participants