fix(compiler): shape re"..." no longer warns W0012 on its own synthesized null - #1997
Merged
Merged
Conversation
…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>
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.
What
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 expectedon theshapeclause -- a warning about anullthe user never wrote.Why
The synthesized read-only shape passed a literal
nullprinter toShapes::regex. W0012's null-to-non-nullable check is correct, by design, for user code that writesnullinto a non-nullable generic position (seeNullToNonNullableSpec,NullToTypeVariableGenericSpec), but it should never fire on compiler-generated code the user has no control over. A new no-printerShapes.regexoverload lets the synthesized call skip the argument entirely instead of passingnullthrough 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
nullto the exactFunction1[R, String]type instead of adding an overload. That cast broke overload resolution forShapes::regex's genericT(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
ShapeRegexNonInvertibleNoWarningSpec(red before the fix, green after).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