Skip to content

Class qualifier removed if same field name in current class exists during assignment #538

@Haberno

Description

@Haberno

Vineflower version

1.12.0 (happens across all versions even fernflower)

Describe the bug

A field in another class with the same name as a field in the current class has its class qualifier removed when it was the target of an assignment.

Additional information

Image

EDIT: Below I just vibe coded and got a working solution but don't know how accurate it is or what other issues it may cause so leaving it to the maintainers the file is AssignmentExprent and method is ToJava.

public TextBuffer toJava(int indent) {
    VarType leftType = left.getInferredExprType(null);

    boolean fieldInClassInit = false, hiddenField = false;
    if (left instanceof FieldExprent) {
      FieldExprent field = (FieldExprent) left;
      ClassNode node = ((ClassNode) DecompilerContext.getContextProperty(DecompilerContext.CURRENT_CLASS_NODE));
      if (node != null) {
        StructField fd = node.classStruct.getField(field.getName(), field.getDescriptor().descriptorString);
        if (fd != null) {
          if (field.getClassname().equals(node.classStruct.qualifiedName)) { // Claude added this if statement to fix it 
            if (field.isStatic() && fd.hasModifier(CodeConstants.ACC_FINAL)) {
              fieldInClassInit = true;
            }
            if (node.getWrapper() != null && node.getWrapper().getHiddenMembers().contains(InterpreterUtil.makeUniqueKey(fd.getName(), fd.getDescriptor()))) {
              hiddenField = true;
            }
          }
        }
      }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions