RFR: 8312163: Crash in dominance check when compiling unnamed patterns

Jan Lahoda jlahoda at openjdk.org
Tue Jul 18 04:52:52 UTC 2023


On Mon, 17 Jul 2023 21:57:07 GMT, Aggelos Biboudis <abimpoudis at openjdk.org> wrote:

> The following fixes a crash in dominance checking involving unnamed patterns by teaching the method `patternDominated` how to handle `AnyPattern` nodes. The test file includes snippets with `_` that need to expose the same behavior as if `var _` was used in all nested positions in place of just `_`.

Looks reasonable to me.

Could be made more compact by using this:

diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
index 57061d38dd8..e6de3f574b3 100644
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java
@@ -4733,10 +4733,13 @@ public class Check {
                     return false;
                 }
             }
-            if (currentPattern instanceof JCBindingPattern) {
-                return existingPattern instanceof JCBindingPattern;
+            if (currentPattern instanceof JCBindingPattern ||
+                currentPattern instanceof JCAnyPattern) {
+                return existingPattern instanceof JCBindingPattern ||
+                       existingPattern instanceof JCAnyPattern;
             } else if (currentPattern instanceof JCRecordPattern currentRecordPattern) {
-                if (existingPattern instanceof JCBindingPattern) {
+                if (existingPattern instanceof JCBindingPattern ||
+                    existingPattern instanceof JCAnyPattern) {
                     return true;
                 } else if (existingPattern instanceof JCRecordPattern existingRecordPattern) {
                     List<JCPattern> existingNested = existingRecordPattern.nested;


in `Check.java`.

-------------

Marked as reviewed by jlahoda (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/14912#pullrequestreview-1534166293


More information about the compiler-dev mailing list