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

Inline local variable refactoring leaves me with compile errors #1859

Open
srikanth-sankaran opened this issue Dec 17, 2024 · 0 comments
Open
Labels
bug Something isn't working

Comments

@srikanth-sankaran
Copy link

I have a piece of code that reads:

	// Return the set of enumerations belonging to the selector enum type that are NOT listed in case statements.
	private Set<FieldBinding> unenumeratedConstants(ReferenceBinding enumType, int constantCount) {
		FieldBinding[] enumFields = ((ReferenceBinding) enumType.erasure()).fields();
		Set<FieldBinding> unenumerated = new HashSet<>(Arrays.asList(enumFields));
		for (int i = 0, max = enumFields.length; i < max; i++) {
			FieldBinding enumConstant = enumFields[i];
			if ((enumConstant.modifiers & ClassFileConstants.AccEnum) == 0) {
				unenumerated.remove(enumConstant);
				continue;
			}
			for (int j = 0; j < constantCount; j++) {
				if (TypeBinding.equalsEquals(this.labelExpressions[j].expression.resolvedType, enumType)) {
					if (this.labelExpressions[j].expression instanceof NameReference reference) {
						FieldBinding field = reference.fieldBinding();
						int intValue = field.original().id;
						if (enumConstant.id == intValue) {
							unenumerated.remove(enumConstant);
							break;
						}
					}
				}
			}
		}
		return unenumerated;
	}

If I chose the intValue in int intValue = field.original().id; and perform inline local variable refactoring I end up with:

if (enumConstant.id == this.field.original().id) {

this is wrong and fails to compile. I was simply expecting: if (enumConstant.id == field.original().id) { where field is a local. It seems field is mistaken to be a field and the this. qualifier is added to it.

@srikanth-sankaran srikanth-sankaran changed the title [ Inline local variable refactoring leaves me with compile errors Dec 17, 2024
@jukzi jukzi added the bug Something isn't working label Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants