Subject: bug#60765: CC Mode 5.35.2 (Java//l); Java incorrect type recognition

From: Alan Mackenzie <[email-masked]>
Date: Mon, 16 Jan 2023 17:56:40 +0000

Hello, Po.

On Fri, Jan 13, 2023 at 09:31:53 +0800, Po Lu via CC-Mode-help wrote:
> Package: cc-mode

> I thought this was only a problem in C Mode, but apparently I'm
> mistaken.

All the modes use the same underlying engine.  ;-)

> Insert the following text into a Java mode buffer:

> class Foo
> {
>   public void
>   viewLayout (int left, int top, int right, int bottom)
>   {
>     int rectWidth, rectHeight;

>     synchronized (this)
>       {
> 	rect.left = left;
> 	rect.top = top;
> 	rect.right = right;
> 	rect.bottom = bottom;
>       }

>     EmacsNative.sendConfigureNotify (this.handle,
> 				     System.currentTimeMillis (),
> 				     left, top, rectWidth,
> 				     rectHeight);
>   }
> }

> go to the line immediately above EmacsNative.sendConfigureNotify.  Then,
> type:

>   TAB r e c t W i d t h;

> `rectHeight' and `viewLayout' will appear in c-found-types.  Thanks.

Yes.  With the "unsafe-maybe" mechanism added to CC Mode late last year,
this was a fairly simple bug to fix.  I've taken the liberty of
committing the fix to the emacs-29 branch with:

commit c1d32d9a20dc94d403725c288d168451b916c034 (HEAD -> emacs-29, origin/emacs-29, origin/HEAD)
Author: Alan Mackenzie <[email-masked]>
Date:   Mon Jan 16 17:44:44 2023 +0000

    CC Mode: Prevent ids in temporary "declarators" getting into c-found-types

, though I haven't yet closed the bug.  I'd be grateful if you could
update your emacs-29 branch with this fix, run your real Java code in
it, and confirm that the bug is indeed fixed.  Thanks!

> Emacs  : GNU Emacs 30.0.50 (build 1, x86_64-pc-linux-gnu)
>  of 2023-01-13
> Package: CC Mode 5.35.2 (Java//l)
> Buffer Style: java
> c-emacs-features: (pps-extended-state col-0-paren posix-char-classes gen-string-delim gen-comment-delim syntax-properties category-properties 1-bit)

-- 
Alan Mackenzie (Nuremberg, Germany).