lahodaj opened a new pull request, #8016:
URL: https://github.com/apache/netbeans/pull/8016

   Consider this code, with a code completion invocation:
   ```
   package test;
   
   public class Test {
       private void test(Runnable r) {
           test(() -> {
               new Base<Void, Void>() {
                   //code completion here
               };
           });
       }
   }
   
   class Base<T1, T2> {
       public T1 test(T1 p) {}
   }
   ```
   
   invoke the code completion at the marked place, and select the "test(Void p) 
- override" option. Nothing will happen, nothing will added to the source code.
   
   The reason is this:
   - there is an (API) `Scope` taken at the place of the cursor. The `Scope`'s 
`Env<AttrContext>` has a `returnResult` filled, and this `returnResult` has a 
`checkContext` that throws exceptions. This is part of method overload 
resolution in javac.
   - the code completion will delegate to 
`GeneratorUtilities.createOverridingMethod`, attempting to create the method.
   - `createOverridingMethod` will try to parse&attribute code like:
   ```
   {
       return super.test(p);
   }
   ```
   in the context of the above `Scope`. But the `return` statement here does 
not match the expected return type from the `Scope`, and so it will go to the 
`checkContext`, and fail with the exception.
   
   This is a bit tricky, as a) the `Scope` here is used in a bit unintended 
way; b) many of the fields and types responsible for this are package private.
   
   The proposal in this PR is to replace the `checkContext` in the 
`returnResult` with the default value (`Check.basicHandler`). That should, 
hopefully, solve this and any other similar problems.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists

Reply via email to