Skip to content

Comments

feat: align field handling w/ Spock#166

Open
pshevche wants to merge 12 commits intomainfrom
claude/kotlin-field-transformations-mT0OD
Open

feat: align field handling w/ Spock#166
pshevche wants to merge 12 commits intomainfrom
claude/kotlin-field-transformations-mT0OD

Conversation

@pshevche
Copy link
Owner

No description provided.

pshevche and others added 11 commits February 15, 2026 13:23
Research how Spock transforms spec fields (instance, @shared, final)
and document the findings as a design record to guide Spockk's
implementation of field handling for lifecycle methods.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add comprehensive compilation tests that validate field transformations
according to Spock's field handling design:

- Instance var/val fields with initializer movement
- Instance lateinit var fields without initialization
- Shared var/val fields with renaming and accessor generation
- Shared lateinit var fields with accessors
- Static fields (should remain untransformed)
- Multiple fields with preserved declaration order
- Field reference replacement in features

Tests are marked with @PendingFeature as field handling is not yet
implemented. These tests serve as the specification for the upcoming
implementation.

Related to #159

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add runtime tests that validate field handling behavior using JUnit
Platform's EngineTestKit:

- Shared field access from subclass
- Shared fields with dollar-prefixed names ($unshared, $shared)
- Shared field getter/setter type compatibility with interfaces
- Shared fields reset between spec runs
- Static fields persist between spec runs

Tests are organized with:
- Test files in flat runtime package
- Test fixture samples in fields/smoke subpackages

Two tests marked @PendingFeature as they require field transformation
implementation. Three tests pass with current behavior.

Related to #159

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
Add smoke test that validates shared fields with different visibility
modifiers (private, protected, public, internal) are accessible from
derived classes.

The test uses an abstract base class with 4 shared fields and 4
feature methods that access them. The derived class simply inherits,
and features run in the derived class context to verify inherited
shared field access works correctly.

This is a natural end-to-end test written in Spockk syntax.

Related to #159

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…formations

Add FieldRewriter that transforms spec fields following Spock conventions:
- Instance var fields: make private, move initializer to $spock_initializeFields
- Instance val fields: rename with $spock_finalField_ prefix, make mutable,
  generate explicit getter delegating to DEFAULT property accessor
- Shared fields: rename with $spock_sharedField_ prefix, make protected volatile,
  route getter/setter through specificationContext.sharedInstance via irAs cast
- Add @FieldMetadata annotations to all fields
- Replace field references in feature methods with getter/setter calls

Also updates SpockkTransformationContextCollector, InternalIdentifiers, and
SpecRewriter to support field context collection and rewriting.

Work in progress: instance field tests pass, shared field expected files
still need updates for correct IR matching.

https://claude.ai/code/session_01EgHR3wxhDRu61RuDX1RBhU
… behavior

- Fix shared field getter/setter to use GET_FIELD/SET_FIELD for override
  fields to avoid infinite recursion when the getter/setter body is
  updated to route through specificationContext.sharedInstance
- Fix backing field visibility: Kotlin backing fields are always private
  even for protected properties
- Add IrStatementOrigin.GET_PROPERTY and IMPLICIT_ARGUMENT origins to
  irGetSharedInstance() to match Kotlin-generated IR
- Cast specificationContext to SpecificationContext (concrete class)
  before calling getSharedInstance() since it's not on ISpecificationContext
- Add registerParentSharedFields() to handle subclass access to parent
  shared fields by mapping fake override getter/setter symbols
- Always create FieldRewriter for spec classes (even with no fields) so
  parent shared field references in subclass features are replaced
- Fix createValFieldSetter to inherit property visibility instead of
  hardcoded PRIVATE
- Remove setSharedField from MultipleFields expected file (source is val)
- Remove @PendingFeature from shared fields reset test (now passing)
- Update expected transformation files with correct annotations,
  declaration order, and cast syntax

https://claude.ai/code/session_01EgHR3wxhDRu61RuDX1RBhU
@github-project-automation github-project-automation bot moved this to Todo in spockk Feb 20, 2026
@pshevche pshevche changed the title chore: bump version for the next release cycle feat: align field handling w/ Spock Feb 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

2 participants