fix(core): Fix subtle inference bug for Input type for some argument shapes - #628
fix(core): Fix subtle inference bug for Input type for some argument shapes#628lbialy wants to merge 3 commits into
Conversation
There was a problem hiding this comment.
🟢 Approval recommended
The change is minimal (union reordering only), aligns with the described failure mode, and is backed by targeted regression tests that validate both static typing and runtime shape.
Pull request overview
This PR fixes a subtle Scala 3 type-inference pitfall around Input’s opaque union types (Input, Input.Optional, Input.OneOrIterable) where, for certain applied arguments (notably resource-constructor-like shapes), the compiler could infer A as Output[R] instead of R, leading to a runtime shape/type mismatch and eventual ClassCastException. The fix preserves binary compatibility by only reordering union alternatives (wrapper-first), and adds targeted regression tests that exercise the previously-missed inference shape.
Changes:
- Reorders union alternatives in
Input,Input.Optional, andInput.OneOrIterableto be wrapper-first, preventing the solver from taking the “bare-A first” shortcut. - Adds a focused regression test suite covering
asOutput,asOptionOutput,asManyOutput, andOutput.wheninference on applied arguments (including runtime-shape assertions).
File summaries
| File | Description |
|---|---|
| core/src/main/scala/besom/internal/Input.scala | Reorders union alternatives for Input/variants to avoid incorrect A := Output[R] inference in certain applied-argument cases. |
| core/src/test/scala/besom/internal/InputInferenceTest.scala | Adds regression tests that detect the prior inference/runtime-shape failure mode and validate correct behavior across key conversion helpers and Output.when. |
Review details
- Files reviewed: 2/2 changed files
- Comments generated: 0
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
as in the topic, minor bug
existing workaround is explicit type either of value passed to the second argument of
whenor directly onwhen[SomeType]this PR fixes this problem for 0.5.2, preserves backward bincompat