<div dir="ltr"><div>I had a question about a particular branch of "same type" checking in the compiler.</div><div><br></div><div>In <a href="https://github.com/openjdk/jdk/blob/jdk-27%2B3/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java#L1430-L1440"><span style="font-family:monospace">TypeEqualityVisitor</span>, when it is testing for "same typeness" with regard to array types</a>, it does the following:</div><div><br></div><div style="margin-left:40px"><span style="font-family:monospace">return s.hasTag(ARRAY)<br>                    && containsTypeEquivalent(t.elemtype, elemtype(s));</span></div><div><br></div><div>So if (<span style="font-family:monospace">t</span> is an array type and) <span style="font-family:monospace">s</span> is an array type and <span style="font-family:monospace">t</span>'s element type contains a type that is equivalent to <span style="font-family:monospace">s</span>'s element type, then <span style="font-family:monospace">t</span> and <span style="font-family:monospace">s</span> are in this case deemed to be the same.</div><div><br></div><div>(<span style="font-family:monospace">containsTypeEquivalent</span> tests to see if <span style="font-family:monospace">t</span> and <span style="font-family:monospace">s</span> <a href="https://github.com/openjdk/jdk/blob/jdk-27%2B3/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java#L4623-L4626">are the same type or contain each other</a>.)</div><div><br></div><div>I'm surprised by the use of <span style="font-family:monospace">containsTypeEquivalent</span> here, since it seems to me that the only way in which it could do anything interesting in this usage beyond applying a "same type" test is if it were possible for an array type's element type to be a wildcard. But this is impossible, so <span style="font-family:monospace">containsTypeEquivalent</span>, when called from this location with these arguments, would seem to always devolve to a simple "same type" check, since <span style="font-family:monospace">containsType</span> <a href="https://github.com/openjdk/jdk/blob/jdk-27%2B3/src/jdk.compiler/share/classes/com/sun/tools/javac/code/Types.java#L1575">devolves to a "same type" test</a> in the presence of non-wildcard arguments.</div><div><br></div><div>After a brief conversation, Dan Smith suggested I write here and see if <span style="font-family:monospace">TypeEqualityVisitor</span>'s <span style="font-family:monospace">visitArrayType</span> method needs to be refactored, or if there's some edge case I'm not seeing (entirely possible), perhaps around error cases and such, that requires this usage of <span style="font-family:monospace">containsTypeEquivalent</span> in the array type code path.</div><div><br></div><div>Happy new year,</div><div>Laird</div><div><br></div><div><br></div></div>