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

Rename property refactoring produces invalid code in @CompileStatic classes #1396

Closed
mauromol opened this issue Sep 23, 2022 · 1 comment
Closed
Assignees
Labels
Milestone

Comments

@mauromol
Copy link

Using Greclipse 4.7.0.v202209190834-e2206.

Consider the following Java class:

package testrefactoring;

public class MyPojo {
	private String foo;
	
	public String getFoo() {
		return foo;
	}
	
	public void setFoo(String foo) {
		this.foo = foo;
	}
}

And the following Groovy class:

package testrefactoring

import groovy.transform.CompileStatic

@CompileStatic
class GClass {

	void foobar() {
		def pojo = new MyPojo()
		println pojo.foo
	}
}

Now, rename MyPojo.foo to MyPojo.bar, ensuring the getter and the setter are renamed as well.
After the renaming occurs, in GClass I see:
println pojo.getBar
which is of course invalid.

The problem goes away if I remove @CompileStatic from GClass.
I'm pretty sure this used to work correctly in the past.

@mauromol mauromol changed the title Property refactoring fails in @CompileStatic Groovy classes (regression?) Property refactoring generates invalid code in @CompileStatic Groovy classes (regression?) Sep 23, 2022
@eric-milles eric-milles self-assigned this Sep 23, 2022
@eric-milles eric-milles added this to the v4.7.0 milestone Sep 23, 2022
@eric-milles eric-milles changed the title Property refactoring generates invalid code in @CompileStatic Groovy classes (regression?) Rename property refactoring produces invalid code in @CompileStatic classes Sep 23, 2022
@eric-milles
Copy link
Member

There are a couple special AST formations that only static compilation uses. I think this is running into one of them since taking away @CompileStatic has it working as expected. I do have a unit test that recreates your result, so it shouldn't take long to get a fix together.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants