Skip to content

Fix unnecessary reflection calls in the generated code #1491

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

Merged
merged 1 commit into from
Dec 7, 2022

Conversation

sofurihafe
Copy link
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unnecessary reflection when one constructor is used more than once
2 participants