Repository navigation
fix(fled): let the compiler check the pixel-format mapping (#4034 D1) - #4349
Conversation
D1 asks callers to use "checked, explicit mapping rather than casting between enums" for fl::fled::PixelFormat -> fl::PixelFormat. toPixelStorage() did that, and then swept four of the six wire formats into `default: return false`. The mapping was checked; nothing checked the mapping was complete. Gray8, Rgba8, Rgbw8 and Rgb565Le are now listed explicitly, so they read as known-and-unmapped rather than possibly-forgotten, and a seventh wire format is a compile error naming this function instead of a silent false found at playback. Verified: adding a probe enumerator gives error: enumeration value 'MutProbe' not handled in switch [-Werror,-Wswitch] against src/fl/fled/detail/pixel_format.cpp.hpp:24. Before, it compiled. bytesPerLed() keeps its default deliberately -- it takes a raw wire byte, not the enum, so it must answer for values that are not enumerators at all. Same lesson as #4340, where a SourceKind switch with no default caught an added source at compile time, and #4341, where three guard lists that could drift silently were made to check each other. bash test --cpp --clean: 304/304 unit, 84/84 examples. bash lint clean. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]> Claude-Session: https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 5 remain after this review. 📝 WalkthroughWalkthrough
ChangesPixel format handling
Priority: ⬇️ Low Estimated code review effort: 2 (Simple) | ~10 minutes Merge Risk: ⚪ Minimal · up to The change preserves current conversion behavior while making future pixel-format additions visible at compile time. 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
#4034's D1 asks callers to use "checked, explicit mapping rather than casting between enums" for
fl::fled::PixelFormat→fl::PixelFormat.toPixelStorage()did exactly that — and then swept four of the six wire formats intodefault: return false. The mapping was checked; nothing checked that the mapping was complete.What changes
Gray8,Rgba8,Rgbw8andRgb565Leare listed explicitly. Two consequences:bytesPerLedalready knows all six, so the asymmetry was real and undocumentedfalsediscovered at playbackVerified
Adding a probe enumerator:
Before the change, the same probe compiled clean.
What deliberately keeps its default
bytesPerLed()takes a raw wire byte, not the enum, so it must answer for values that are not enumerators at all. Itsdefault: return 0is doing real work and stays.Why this is worth a PR on its own
Same lesson as two earlier ones this cycle, from opposite directions:
SourceKindswitch with no default caught an added source at compile time, which is how the corpus change was kept honestThis is the third: a mapping that was correct today and had no way to stay correct. The fix is to let the compiler hold it rather than a reader.
bash test --cpp --clean: 304/304 unit, 84/84 examples.bash lintclean.🤖 Generated with Claude Code
https://claude.ai/code/session_01MLhWkMfzLjrnLTDMBE6Fj9
Summary by CodeRabbit