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

Issue #13086: InnerAssignmentCheck failed for one line code in Java 1… #13090

Closed

Conversation

Andromeda227799
Copy link

@Andromeda227799 Andromeda227799 commented May 25, 2023

Fixing Issue #13086 by allowing Expressions to have switch cases as parent AST

Diff Regression config: https://gist.githubusercontent.com/Andromeda227799/52c0c74faeb9ba9334955fc68b624e98/raw/8ff5e9484d8c48022d9817fd299a1c5b6b644e71/check.xml

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please generate regression diff report.
Example how to do this: #13085
full doc: https://github.com/checkstyle/contribution/tree/master/checkstyle-tester#report-generation

items:

@Andromeda227799
Copy link
Author

GitHub, generate report

@Andromeda227799 Andromeda227799 force-pushed the shamith-fix/13086 branch 3 times, most recently from ea81f62 to 7965389 Compare May 27, 2023 10:07
@@ -33,6 +33,20 @@ void innerAssignments()
}
}

public void expressionCanHaveParentSwitchCaseIssue13086()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not extend existing inputs. We need to create a completely new test and test input using switch statements, switch expressions, with both switch rules and labeled block statements. You will need to create the new input in resources-noncompilable in order to support syntax greater than jdk11.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, please create new Input file, this input file is already too big.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please in addition add test case from user, to be absolutely clear that user reported case is covered

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nrmancuso @romani This issue also exists when I ran with Java 11, so should I simply create a new test file in src/test/resources/com/puppycrawl/tools/checkstyle/checks/coding/innerassignment instead of adding it in resources-noncompilable

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, we must include exact case from issue report.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Andromeda227799 always allow reviewers to resolve their items, please just reply to each with “done” or discussion if necessary.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@nrmancuso
Copy link
Member

@Andromeda227799 you have not supplied a configuration, so no report will be generated. Please read https://github.com/checkstyle/contribution/tree/master/checkstyle-tester#report-generation

@Andromeda227799
Copy link
Author

GitHub, generate report

@github-actions
Copy link
Contributor

Report generation failed on phase "make_report",
step "Generate report".
Link: https://github.com/checkstyle/checkstyle/actions/runs/5102549215

@Andromeda227799
Copy link
Author

Report generation failed on phase "make_report", step "Generate report".Link: https://github.com/checkstyle/checkstyle/actions/runs/5102549215

@romani could you help me with why this failed?

@nrmancuso
Copy link
Member

@Andromeda227799 you can click into link provided by GitHub action to see point of failure, looks like your configuration is not valid.

@Andromeda227799 Andromeda227799 force-pushed the shamith-fix/13086 branch 4 times, most recently from 8c32701 to dfbaccb Compare May 28, 2023 09:40
@Andromeda227799
Copy link
Author

GitHub, generate report

@github-actions
Copy link
Contributor

github-actions bot commented Jun 5, 2023

Report generation failed on phase "make_report",
step "Generate report".
Link: https://github.com/checkstyle/checkstyle/actions/runs/5174846776

@Andromeda227799
Copy link
Author

GitHub, generate report

1 similar comment
@Andromeda227799
Copy link
Author

GitHub, generate report

@github-actions
Copy link
Contributor

github-actions bot commented Jun 5, 2023

Report generation failed on phase "make_report",
step "Generate report".
Link: https://github.com/checkstyle/checkstyle/actions/runs/5175951691

@Andromeda227799
Copy link
Author

GitHub, generate report

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

void method(final String operation) {
boolean flag = false;
switch (operation) {
case "Y" -> flag = true; // ok
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove trailing comment // ok
I know there are a lot of examples where we have them, but it is our mistake of past.
No // violation means ok, so //ok is just a noise.

@romani
Copy link
Member

romani commented Jun 6, 2023

@Andromeda227799 , please look at my request above to extend Inputs , thanks in advance.

@nrmancuso
Copy link
Member

nrmancuso commented Jun 6, 2023

We lost some valid violations, example:
https://checkstyle-diff-reports.s3.us-east-2.amazonaws.com/dfbaccb_2023153903/reports/diff/openjdk17/xref/home/runner/work/checkstyle/checkstyle/.ci-temp/contribution/checkstyle-tester/repositories/openjdk17/test/langtools/tools/javac/switchexpr/DefiniteAssignment1.java.html#L404

We need to differentiate between assignment in switch expression (should be violation) and switch statements (should not be a violation).

This should be expected behavior:

public class Test {

    private boolean flag;

    void getOperationOk(final String operation) {
        switch (operation) {
            case "Y" -> flag = true;  // should not be violation
            case "N" -> {
                flag = false; // ok
            }
            default -> throw new UnsupportedOperationException();
        }
    }

    void getOperationViolation1(final String operation) {

        final boolean result = switch (operation) {
            case "Y" -> flag = true;  // should be violation
            case "N" -> {
                yield flag = false; // should be violation
            }
            case "Z" -> {
                flag = false;
                yield flag; // ok
            }
            default -> throw new UnsupportedOperationException();
        };
    }

        void getOperationViolation2(final String operation) {

        final boolean result = switch (operation) {
            case "Y" : flag = true;  // should be violation
            case "N" : {
                yield flag = false; // should be violation
            }
            case "Z" : {
                flag = false;
                yield flag; // ok
            }
            default : throw new UnsupportedOperationException();
        };
    }
}

@pmensalt
Copy link

pmensalt commented Aug 7, 2023

Is there any update or advancement regarding this issue?

@nrmancuso
Copy link
Member

@Andromeda227799 do you plan to continue to work on this issue?

Is there any update or advancement regarding this issue?

@pmensalt looks like we might have lost contact with the author of this PR, let's see if they respond.

@romani
Copy link
Member

romani commented Sep 2, 2023

if no activity before 1 october , we will close PR and next contributor can reuse this code and complete update

@nrmancuso
Copy link
Member

We have lost contact with contributor, anyone is welcome to reuse changes here to resolve issue.

@AayushSaini101
Copy link
Contributor

@nrmancuso "We need to differentiate between assignment in switch expression (should be violation) and switch statements (should not be a violation)." Regarding this can you guide me a little bit on how can we add these? We have added the Switch rule {TokenTypes.EXPR, TokenTypes.SWITCH_RULE}, but do i need to create new rule for the second condition that is final boolean result = switch (operation) {

@nrmancuso
Copy link
Member

@AayushSaini101 let’s open a new PR, please leave comments in your PR with what you are struggling with

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

Successfully merging this pull request may close these issues.

None yet

6 participants