Skip to content

Preserve the type of recorded condition values - #2435

Closed
mvanhorn wants to merge 1 commit into
spockframework:masterfrom
mvanhorn:fix/2343-preserve-recorded-value-type
Closed

mvanhorn wants to merge 1 commit into
spockframework:masterfrom
mvanhorn:fix/2343-preserve-recorded-value-type

Conversation

@mvanhorn

Copy link
Copy Markdown

ValueRecorder.record now uses a type parameter for its argument and return value, preserving the recorded expression's static type without changing the recording logic. Regression coverage exercises properties and public fields across then, expect, and explicit assertions in when. Under @TypeChecked, accessing a spec field or property through explicit this in a condition can fail compilation because the receiver is treated as Object. This affects then and expect conditions, as well as explicit assertions in when blocks.

The testClasses build completed successfully; the transcript shows compilation, not test execution.

Fixes #2343

AI was used for assistance.

ValueRecorder.record now uses a type parameter for its argument and
return value, preserving the recorded expression's static type without
changing the recording logic. Regression coverage exercises properties
and public fields across then, expect, and explicit assertions in when.
Additional cases check that failing conditions still record the
receiver, operands, and result for both string and null values.

Fixes spockframework#2343
@coderabbitai

coderabbitai Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 7dbae22c-864d-48fe-b906-7e2ac9c4a286

📥 Commits

Reviewing files that changed from the base of the PR and between ce7e8af and 26a3b17.


📒 Files selected for processing (2)
  • spock-core/src/main/java/org/spockframework/runtime/ValueRecorder.java
  • spock-specs/src/test/groovy/org/spockframework/smoke/StaticTypeChecking.groovy

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.



📝 Walkthrough

Walkthrough

ValueRecorder.record now returns the generic type of its input value. Regression tests cover statically checked conditions that reference specification fields and verify recorded values after a condition fails.

Changes

Typed condition recording

Layer / File(s) Summary
Preserve receiver types in conditions
spock-core/src/main/java/org/spockframework/runtime/ValueRecorder.java, spock-specs/src/test/groovy/org/spockframework/smoke/StaticTypeChecking.groovy
ValueRecorder.record now returns its input value’s type. Tests cover private and public fields across several condition forms and check the values recorded when a condition fails.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium


Merge Risk: ⚪ Minimal · up to 26a3b

No actionable merge-blocking issue is established. Run the new regression tests as part of normal validation.

Pre-merge checks | Passed 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preserving the type of values recorded by ValueRecorder.record.
Description check Passed The description accurately explains the ValueRecorder.record type change, the related @TypeChecked regression, test coverage, and build result.
Linked Issues check Passed The change addresses issue #2343. ValueRecorder.record now returns the generic type T of its input, so static type checking can preserve the receiver type after recording. The regression tests cov…
Out of Scope Changes check Passed The pull request changes only ValueRecorder.record and adds focused regression tests in StaticTypeChecking for issue #2343. The tests directly validate the required type preservation and condition…
Docstring Coverage Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 1 files. (1 skipped: 1 …

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

A rabbit reads the types in line
And finds the field where values shine
The recorder gives the same type back
Conditions stay on the proper track
I hop away with tests in tow

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

RetriggerConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no actionable issues were found.

Summary

ValueRecorder.record now uses <T> for its argument and return value, preserving static type information without changing how values are stored.

  • Type-checked conditions keep the types of recorded expressions.

Reviews (1) · Last reviewed commit: "Preserve the type of recorded condition ..." · Reviewed by Greptile

@Vampire

Vampire commented Oct 10, 2026

Copy link
Copy Markdown
Member

Thanks, but there is waaaay more necessary to properly support STC, and we are already working on it in #2397, so I'm closing this as duplicate.

@Vampire Vampire closed this Oct 10, 2026
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.

Reference to field or property with explicit this in then block

2 participants