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 #13850

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public class InnerAssignmentCheck
TokenTypes.RESOURCE_SPECIFICATION,
},
{TokenTypes.EXPR, TokenTypes.LAMBDA},
{TokenTypes.EXPR, TokenTypes.SWITCH_RULE},
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,14 @@ public void testInnerAssignmentNotInLoopContext() throws Exception {
expected);
}

@Test
public void testInnerAssignmentWithEnhancedSwitch() throws Exception {
final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
verifyWithInlineConfigParser(
getNonCompilablePath("InputInnerAssignmentWithEnhancedSwitch.java"),
expected);
}

@Test
public void testTokensNotNull() {
final InnerAssignmentCheck check = new InnerAssignmentCheck();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
InnerAssignment


*/
package com.puppycrawl.tools.checkstyle.checks.coding.innerassignment;

//non-compiled with javac: Compilable with Java14
public class InputInnerAssignmentWithEnhancedSwitch {

void method(final String operation) {
boolean flag = false;
switch (operation) {
case "Y" -> flag = true;
case "N" -> {
flag = false;
}
default -> throw new UnsupportedOperationException();
}
}
}