Skip to content

Reference to field or property with explicit this in then block #2343

@eric-milles

Description

@eric-milles

Describe the bug

Making a reference to the spec's field or property using explicit-this in the then block produces an STC error. No error shows for this.myField in the when block.

this.myField in the then is written as $spock_valueRecorder.record($spock_valueRecorder.startRecordingValue(0), this).myField in the feature method. record returns Object, so as far as STC is concerned, it can't find the property "myField" in java.lang.Object.

Spock 2.4
Groovy 5.0.5

To Reproduce

@groovy.transform.TypeChecked
class SomeSpec extends Specification {
  String myField
  void testField() {
   when:
    this.myField = 'test'
   then:
    this.myField == 'test' // [Static type checking] - No such property: myField for class: java.lang.Object
  }
}

Expected behavior

this.myField checks properly or is exempted from STC in when, then, expect, etc.

Actual behavior

"[Static type checking] - No such property: myField for class: java.lang.Object"

Java version

Java 25.0.2

Buildtool version

Eclipse 2026-06 / Groovy 5.0.5

What operating system are you using

Windows

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions