Skip to content

Issue #14946: False negative in IllegalTypeCheck on record pattern#14991

Merged
rnveach merged 1 commit into
checkstyle:masterfrom
checkstyle-GSoC25:illegaltype
Jun 22, 2024
Merged

Issue #14946: False negative in IllegalTypeCheck on record pattern#14991
rnveach merged 1 commit into
checkstyle:masterfrom
checkstyle-GSoC25:illegaltype

Conversation

@mahfouz72

Copy link
Copy Markdown
Member Author

Github, generate report

@mahfouz72

Copy link
Copy Markdown
Member Author

Github, generate site

@github-actions

Copy link
Copy Markdown
Contributor

LinkedHashMap<Integer, Integer> l2
= new LinkedHashMap<>();

Box<LinkedHashMap<Integer,Integer>> box = new Box<>(l2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Guess this is more me being curious. Since we are changing pattern defs, it would make things easier to only see pattern def violations in this file. This is what lead me to my next curious question.

Would changing these 2 statements to the following, and leaving the rest of the code the same still compile?

        Map<Integer, Integer> l2 = new LinkedHashMap<>();

        Box<Map<Integer,Integer>> box = new Box<>(l2);

Would that mean we could have different type checks:

if (box instanceof Box<LinkedHashMap<Integer,Integer>>(var linkedHashMap)) {}

if (box instanceof Box<HashMap<Integer,Integer>>(var hashMap)) {}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Would changing these 2 statements to the following, and leaving the rest of the code the same still compile?

        Map<Integer, Integer> l2 = new LinkedHashMap<>();

        Box<Map<Integer,Integer>> box = new Box<>(l2);

Nope.

Inconvertible types; cannot cast 'com.puppycrawl.tools.checkstyle.checks.coding.illegaltype.InputIllegalTypeWithRecordPattern.Box<java.util.Map<java.lang.Integer,java.lang.Integer>>' to 'com.puppycrawl.tools.checkstyle.checks.coding.illegaltype.InputIllegalTypeWithRecordPattern.Box<java.util.LinkedHashMap<java.lang.Integer,java.lang.Integer>>'

@rnveach rnveach merged commit 97cfea3 into checkstyle:master Jun 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects

Development

Successfully merging this pull request may close these issues.

Add Check Support for Java 21 Record Pattern : IllegalType

3 participants