eclipse-jdt / eclipse.jdt.core

Eclipse Public License 2.0
161 stars 129 forks source link

Diamond shouldn't be allowed in pattern #3157

Open stephan-herrmann opened 4 hours ago

stephan-herrmann commented 4 hours ago

From https://github.com/eclipse-jdt/eclipse.jdt.core/pull/3069#discussion_r1798802924:

It seems that this snippet:

if (p instanceof R<>(String a))

is actually illegal syntax.

Diamond syntax is defined in

ClassOrInterfaceTypeToInstantiate:
   {Annotation} Identifier {. {Annotation} Identifier}
   [TypeArgumentsOrDiamond]

TypeArgumentsOrDiamond:
   TypeArguments
   <>

But the instanceof rule doesn't seem to have a path into that rule, start the search from

InstanceofExpression:
   RelationalExpression instanceof ReferenceType
stephan-herrmann commented 3 hours ago

The diamond operator was added in your grammar via 699cc351 (merge), orginally 0e080153. Unfortunately no bug with any discussion was linked. I wonder if the grammar corresponds to what specification we had at that time, or if perhaps the grammar was intentionally made more permissive, to allow for better error messages?