Skip to content

Commit

Permalink
Use the type of the field instead of using Object as the return type …
Browse files Browse the repository at this point in the history
…when generating getters for shared fields.

Fixes #570.
  • Loading branch information
erdi committed Feb 26, 2016
1 parent bf61631 commit 4e15987
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
Expand Up @@ -103,7 +103,7 @@ private void createSharedFieldGetter(Field field) {

BlockStatement getterBlock = new BlockStatement();
getter = new MethodNode(getterName, determineVisibilityForSharedFieldAccessor(field) | Opcodes.ACC_SYNTHETIC,
ClassHelper.DYNAMIC_TYPE, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, getterBlock);
field.getAst().getType(), Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, getterBlock);

getterBlock.addStatement(
new ReturnStatement(
Expand Down
Expand Up @@ -61,4 +61,27 @@ class Foo extends Specification {
then:
noExceptionThrown()
}

@Issue("https://github.com/spockframework/spock/issues/570")
def 'getters and setters generated for shared fields use the declared type of the field'() {
when:
runner.runWithImports '''
class ImplementsInterface extends Specification implements HasValueProperty {
@Shared String value = "1"
def test() {
expect:
value == "1"
}
}
interface HasValueProperty {
String getValue()
void setValue(String value)
}
'''

then:
noExceptionThrown()
}
}

0 comments on commit 4e15987

Please sign in to comment.