From 735b18bac95ba49b350cb38725d8e9dfec8067ba Mon Sep 17 00:00:00 2001 From: Rick Ossendrijver Date: Fri, 1 Mar 2024 15:55:36 +0100 Subject: [PATCH] `InstanceOfPatternMatch`: introduce failing unit test --- .../InstanceOfPatternMatchTest.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/test/java/org/openrewrite/staticanalysis/InstanceOfPatternMatchTest.java b/src/test/java/org/openrewrite/staticanalysis/InstanceOfPatternMatchTest.java index 0d29e191f..8c36f75ea 100644 --- a/src/test/java/org/openrewrite/staticanalysis/InstanceOfPatternMatchTest.java +++ b/src/test/java/org/openrewrite/staticanalysis/InstanceOfPatternMatchTest.java @@ -791,5 +791,32 @@ String test(Object o) { ) ); } + + @Test + void multipleCastsInDifferent() { + rewriteRun( + //language=java + java( + """ + import java.util.Comparator; + public class A { + Comparator comparator() { + return (a, b) -> + (a instanceof String) && (b instanceof String) ? ((String) a).compareTo((String) b) : 0; + } + } + """, + """ + import java.util.Comparator; + public class A { + Comparator comparator() { + return (a, b) -> + (a instanceof String s) && (b instanceof String s) ? s.compareTo(s) : 0; + } + } + """ + ) + ); + } } }