Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot compile valid Groovy code due to final variable not seen as having been initialized #1017

Open
renatoathaydes opened this issue Aug 27, 2019 · 1 comment

Comments

@renatoathaydes
Copy link

commented Aug 27, 2019

Issue description

Valid Groovy class cannot be compiled (worked fine before upgrade) because a final variable is seen as possibly not initialized in the cleanup block.

How to reproduce

Attempt to compile this spec:

import spock.lang.Specification

class Broken3 extends Specification {
    def "test"() {
        final value = 'hello'

        expect:
        value.size() > 3

        cleanup:
        clean value
    }

    def clean(v) {}
}

Run:

./gradlew compileTestGroovy

Error:

> Task :compileTestGroovy FAILED
startup failed:
/Users/renato/programming/projects/spock-tests/src/test/groovy/Broken3.groovy: 11: The variable [value] may be uninitialized
. At [11:15]  @ line 11, column 15.
           clean value
                 ^

Expected outcome

Should compile ok.

Additional Environment information

From ./gradlew --version:

------------------------------------------------------------
Gradle 5.2.1
------------------------------------------------------------

Build time:   2019-02-08 19:00:10 UTC
Revision:     f02764e074c32ee8851a4e1877dd1fea8ffb7183

Kotlin DSL:   1.1.3
Kotlin:       1.3.20
Groovy:       2.5.4
Ant:          Apache Ant(TM) version 1.9.13 compiled on July 10 2018
JVM:          1.8.0_181 (Azul Systems, Inc. 25.181-b02)
OS:           Mac OS X 10.14.6 x86_64

Also attempted with Oracle's JVM and the result is the same:

JVM:          1.8.0_171 (Oracle Corporation 25.171-b11)

Groovy/Spock version

dependencies {
    compile 'org.spockframework:spock-core:1.3-groovy-2.5'
}
@renatoathaydes

This comment has been minimized.

Copy link
Author

commented Aug 27, 2019

Also tried with JVM version 12, and the result is the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.