GNU bug report logs - #23901
CC Mode 5.33 (Java/l); Wrong indentation of fallthrough switch/case with strings

Previous Next

Package: cc-mode;

Reported by: Åsmund Grammeltvedt <asmundg <at> big-oil.org>

Date: Tue, 5 Jul 2016 20:04:02 UTC

Severity: normal

Done: Alan Mackenzie <acm <at> muc.de>

Bug is archived. No further changes may be made.

Full log


Message #16 received at 23901 <at> debbugs.gnu.org (full text, mbox):

From: Jostein Kjønigsen <jostein <at> secure.kjonigsen.net>
To: Alan Mackenzie <acm <at> muc.de>,
 Åsmund Grammeltvedt <asmundg <at> big-oil.org>
Cc: 23901 <at> debbugs.gnu.org
Subject: Re: bug#23901: CC Mode 5.33 (Java/l);
 Wrong indentation of fallthrough switch/case with strings
Date: Wed, 06 Jul 2016 15:56:39 +0200
On Wed, Jul 6, 2016, at 01:55 PM, Alan Mackenzie wrote:
> Hello, Åsmund.
> 
> On Tue, Jul 05, 2016 at 09:37:15PM +0200, Åsmund Grammeltvedt wrote:
>> Hi!
> 
>> Running indent-region on the following code produces wrong indentation
>> on all but the first statement in the last switch block.
> 
> OK.
> 
>> I have included two cases that work correctly for comparison:
> 
> Thank you for such a clear description of the fault, and thanks also for
> including a CC Mode configuration dump (from C-c C-b).
> 
>> class Foo {
>>     public void Bar(String foo) {
>>         int a = 0;
> 
>>         switch (a) {
>>         case 0:
>>         case 1:
>>             a += 1;
>>             a += 2;
>>             break;
>>         }
> 
>>         switch (foo) {
>>         case "foo":
>>             a += 1;
>>             a += 2;
>>             break;
>>         }
> 
>>         switch (foo) {
>>         case "foo":
>>         case "bar":
>>             a += 1;
>>         a += 2;
>>         break;
>>         }
>>     }
>> }
> 
> The problem appears to be in the CC Mode variable
> `c-nonlabel-token-key', which specifies things which can't be in a
> label.  The Java value includes the character '"', presumably from a
> period in ancient history when strings in Java couldn't be case labels.
> 
> Please try out the following fix, and please confirm that it has fixed
> the bug, or tell me what is still not right.  The file cc-langs.el is in
> the directory ..../lisp/progmodes/.
> 
> Note that after applying the patch, you need to recompile, at the very
> least, cc-langs.el, cc-fonts.el, cc-engine.el, cc-mode.el.  (Or just
> recompile all of cc-*.el).
> 
> 
> diff -r 2fcfc6e054b3 cc-langs.el
> --- a/cc-langs.el       Sun Jul 03 17:54:20 2016 +0000
> +++ b/cc-langs.el       Wed Jul 06 11:45:48 2016 +0000
> @@ -3233,8 +3233,8 @@
> (append (c-lang-const c-label-kwds)
> (c-lang-const c-protection-kwds))
> :test 'string-equal)))
> -  ;; Don't allow string literals, except in AWK.  Character constants
> are OK.
> -  (c objc java pike idl) (concat "\"\\|"
> +  ;; Don't allow string literals, except in AWK and Java.  Character
> constants are OK.
> +  (c objc pike idl) (concat "\"\\|"
> (c-lang-const c-nonlabel-token-key))
> ;; Also check for open parens in C++, to catch member init lists in
> ;; constructors.  We normally allow it so that macros with arguments
> 
> 
>> Emacs  : GNU Emacs 25.1.50.2 (x86_64-pc-linux-gnu, GTK+ Version 3.10.8)
>> of 2016-04-15
>> Package: CC Mode 5.33 (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 1-bit)
> 
> [ CC Mode state appreciated and snipped. ]
> 
>> --
>> Åsmund Grammeltvedt
> 
> --
> Alan Mackenzie (Nuremberg, Germany).

Hey Alan.

Thanks for the excellent response.

Quick dislaimer: I'm the current csharp-mode maintainer, and this bug
was
originally issued for csharp-mode. As we discovered the same bug was
found
in java-mode which csharp-mode is based on, we suggested reporting the
error
upstream.

I can confirm that this patch does indeed fix the indentation issue,
also in
csharp-mode, but unfortunately it seems to have some side-effects
besides just
indentation.

csharp-mode has a small suite of automated test to verify behaviour,
fontification, indentation, imenu-results, etc.

After applying your patch and recompiling all cc-mode *.el-files, two of
our
tests which used to be OK are now failing. They're both related to
fontification: one for #compiler directives and another for
string-literal
termination.

To me, these kind of side-effects seems a bit unexpected. Would it be OK
to ask
you for some feedback? Basically all you need to reproduce is doing the
following:

> git clone https://github.com/josteink/csharp-mode
> cd csharp-mode
> make clean && make test

I don't want to bother you too much with third-party code, but thought
you may
find it interesting none the less, since this may also affect other
cc-mode
derived modes.

--
Jostein Kjønigsen
jostein <at> kjonigsen.net / jostein <at> secure.kjonigsen.net




This bug report was last modified 8 years and 355 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.