<div dir="ltr">This feels like a bug to me too, I'd expect type annotations on var lambda parameters to either be rejected, or accepted and included in the output, but not accepted and then ignored.<div><br></div><div>I wonder if this could have been an oversight, and JLS <span style="color:rgb(0,0,0)">9.7.4 should be updated to include lambda parameters that use var. Does anyone on the list remember discussion about this type annotation edge case from JEP 323?</span></div><div><span style="color:rgb(0,0,0)"><br></span></div>Looking at the handling of var locals in javac, I think the reason it doesn't also reject var lambda parameters is that their type is inferred earlier, so the check for `s.type.hasTag(NONE)` is false: <a href="https://github.com/openjdk/jdk/blob/f872467d69a6d8442f8004609ce819641cab568b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java#L3425">https://github.com/openjdk/jdk/blob/f872467d69a6d8442f8004609ce819641cab568b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Check.java#L3425</a></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 19, 2022 at 4:09 AM Chris Povirk <<a href="mailto:cpovirk@google.com">cpovirk@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>Since type-use annotations are rejected on var local variables, I would have expected them to be rejected on var lambda parameters, too.</div></div></blockquote><div><br></div><div>That position fits with the idea that, when we use var, we're expecting the full type to be inferred.</div><div><br></div><div>In contrast, if it *were* possible to put annotations on var, there would be ambiguity about what the *absence* of an annotation means: Does it mean "Please infer whether an annotation should be present on the inferred type," or does it mean "Behave as if no annotation is present on the inferred type?"</div><div><br></div><div>The conservative approach for developers would be to annotate *every* var declaration. But, in addition to being verbose, that approach is possible for our nullness work only if every type is either nullable or non-null—and that's not the case, since a type-variable usage T has a nullness that will depend on the type argument.</div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
</blockquote></div></div>
</blockquote></div>