Skip to content

fix(core): Fix subtle inference bug for Input type for some argument shapes - #628

Open
lbialy wants to merge 3 commits into
mainfrom
fix/input-inference-subtle-bugs
Open

fix(core): Fix subtle inference bug for Input type for some argument shapes#628
lbialy wants to merge 3 commits into
mainfrom
fix/input-inference-subtle-bugs

Conversation

@lbialy

@lbialy lbialy commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

as in the topic, minor bug

existing workaround is explicit type either of value passed to the second argument of when or directly on when[SomeType]

this PR fixes this problem for 0.5.2, preserves backward bincompat

@lbialy lbialy added this to the 0.5.2 milestone Sep 3, 2026
@lbialy
lbialy requested a lite review from Copilot September 3, 2026 13:10
@lbialy lbialy added kind/bug Some behavior is incorrect or out of spec kind/improvement An improvement with existing workaround area/core The SDK's core code size/S Estimated effort to complete (1-2 days). P2 Bugs of moderate severity to be assigned to an engineer in the next iteration labels Sep 3, 2026

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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, and Input.OneOrIterable to be wrapper-first, preventing the solver from taking the “bare-A first” shortcut.
  • Adds a focused regression test suite covering asOutput, asOptionOutput, asManyOutput, and Output.when inference 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/core The SDK's core code kind/bug Some behavior is incorrect or out of spec kind/improvement An improvement with existing workaround P2 Bugs of moderate severity to be assigned to an engineer in the next iteration size/S Estimated effort to complete (1-2 days).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants