Skip to content

Fix unnecessary reflection calls in the generated code#1491

Merged
EgorkaKulikov merged 1 commit into
mainfrom
andrey-t/unnecessary-reflection-calls
Dec 7, 2022
Merged

Fix unnecessary reflection calls in the generated code#1491
EgorkaKulikov merged 1 commit into
mainfrom
andrey-t/unnecessary-reflection-calls

Conversation

@sofurihafe

Copy link
Copy Markdown
Member

Description

This PR fixes unnecessary reflection calls as described in the following issue and infinite loop in self-reference initialization (there are examples in the manual testing section).

Fixes # (1353)

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Automated Testing

UTBot-samples.

Manual Scenario

Tested on the code attached in the issue. Additionally, tested self-reference cases like the following:

// First scenario
class FirstClass {
    SecondClass secondClass;

    FirstClass(SecondClass second) {
        this.secondClass = second;
    }
}

class SecondClass {
    FirstClass firstClass;

    SecondClass(FirstClass first) {
        this.firstClass = first;
    }
}

class ClassWithCrossReferenceRelationship {
    public FirstClass returnFirstClass(int value) {
        if (value == 0) {
            return new FirstClass(new SecondClass(null));
        } else {
            FirstClass first = new FirstClass(null);
            first.secondClass = new SecondClass(first);

            return first;
        }
    }
}



// Second scenario
class FirstClass1 {
    ThirdClass1 thirdClass;

    FirstClass1(ThirdClass1 third) {
        this.thirdClass = third;
    }
}

class SecondClass1 {
    FirstClass1 firstClass;

    SecondClass1(FirstClass1 first) {
        this.firstClass = first;
    }
}

class ThirdClass1 {
    SecondClass1 secondClass;

    ThirdClass1(SecondClass1 second) {
        this.secondClass = second;
    }
}

class ClassWithCrossReferenceRelationship1 {
    public FirstClass1 returnFirstClass(int value) {
        FirstClass1 first = new FirstClass1(null);
        SecondClass1 second = new SecondClass1(first);
        ThirdClass1 third = new ThirdClass1(second);
        first.thirdClass = third;

        return first;
    }
}
@sofurihafe sofurihafe force-pushed the andrey-t/unnecessary-reflection-calls branch from 1f99a2c to de865a5 Compare December 7, 2022 20:05
@EgorkaKulikov EgorkaKulikov merged commit e1dd1d1 into main Dec 7, 2022
@EgorkaKulikov EgorkaKulikov deleted the andrey-t/unnecessary-reflection-calls branch December 7, 2022 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants