Issue #14946: False negative in IllegalTypeCheck on record pattern#14991
Conversation
|
Github, generate report |
|
Github, generate site |
| LinkedHashMap<Integer, Integer> l2 | ||
| = new LinkedHashMap<>(); | ||
|
|
||
| Box<LinkedHashMap<Integer,Integer>> box = new Box<>(l2); |
There was a problem hiding this comment.
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)) {}
There was a problem hiding this comment.
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>>'
closes #14946 :
added
RECORD_PATTERN_DEFtoken toIllegalTypeCheckDiff Regression config: https://gist.githubusercontent.com/mahfouz72/afd57aa6e51ca161b7927acd959e5211/raw/d09e02f562fa0cd9e71eebcc4f9ab6fd09a4fd36/check.xml
Diff Regression patch config: https://gist.githubusercontent.com/mahfouz72/33967bf86e4a29cafa429771b0e95808/raw/efa32547d82e4b966268643d284182774d68bfdd/check_patch.xml
Diff Regression projects: https://gist.githubusercontent.com/mahfouz72/a3d0af030c8f5efd0d8a39f2c14750bc/raw/8ca3493f88bc1003db86b40015a4c2101ab7bc94/projects-to-test-on.properties