public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug modula2/114520] New: Incorrect ordering of import/export statements cause confusing error messages
@ 2024-03-28 15:46 gaius at gcc dot gnu.org
  2024-03-28 15:46 ` [Bug modula2/114520] " gaius at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-03-28 15:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114520

            Bug ID: 114520
           Summary: Incorrect ordering of import/export statements cause
                    confusing error messages
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: modula2
          Assignee: gaius at gcc dot gnu.org
          Reporter: gaius at gcc dot gnu.org
  Target Milestone: ---

As reported on the gm2 mailing list:

$ cat localmodule2.mod
MODULE localmodule2 ;

FROM libc IMPORT printf ;

PROCEDURE mult2 (n: CARDINAL) : CARDINAL ;
BEGIN
   RETURN 2*n
END mult2 ;

MODULE local ;

  EXPORT mysqr ;
  IMPORT mult2 ;

  PROCEDURE mysqr (n: CARDINAL) : CARDINAL ;
  BEGIN
     RETURN mult2 (n) * mult2 (n)
  END mysqr ;

END local ;

VAR
   d: CARDINAL ;
BEGIN
   d := mysqr (3) ;
   printf ("sqr (3 * 2) = %d\n", d)
END localmodule2.


$ gm2 localmodule2.mod 
localmodule2.mod:13:10: warning: In inner module ‘local’: syntax warning, ‘END’
missing 
   13 |   IMPORT mult2 ;
      |          ^~~~~
localmodule2.mod:20:11: warning: In program module ‘localmodule2’: syntax
warning, ‘.’ missing 
   20 | END local ;
      |           ^
localmodule2.mod:1:8: error: module name at beginning ‘localmodule2’ does not
match the name at end ‘local’
    1 | MODULE localmodule2 ;
      |        ^~~~~~~~~~~~
localmodule2.mod:10:8: error: In inner module ‘local’: module name at beginning
‘local’ does not match the name at end ‘mult2’
   10 | MODULE local ;
      |        ^~~~~
localmodule2.mod:13:3: error: syntax error, found ‘IMPORT’
   13 |   IMPORT mult2 ;
      |   ^~~~~~
localmodule2.mod:13:10: error: module name at end ‘mult2’ does not match the
name at beginning ‘local’
   13 |   IMPORT mult2 ;
      |          ^~~~~
localmodule2.mod:20:5: error: In program module ‘localmodule2’: module name at
end ‘local’ does not match the name at beginning ‘localmodule2’
   20 | END local ;
      |     ^~~~~
localmodule2.mod:20:11: error: syntax error, found ‘;’
   20 | END local ;
      |           ^
localmodule2.mod:28:1: error: no scope active: compilation failed


The user level fix is to switch the IMPORT and EXPORT statement lines.
However the compiler should generate a more meaningful error message.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug modula2/114520] Incorrect ordering of import/export statements cause confusing error messages
  2024-03-28 15:46 [Bug modula2/114520] New: Incorrect ordering of import/export statements cause confusing error messages gaius at gcc dot gnu.org
@ 2024-03-28 15:46 ` gaius at gcc dot gnu.org
  2024-03-28 16:25 ` gaius at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-03-28 15:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114520

Gaius Mulley <gaius at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-03-28

--- Comment #1 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Confirmed.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug modula2/114520] Incorrect ordering of import/export statements cause confusing error messages
  2024-03-28 15:46 [Bug modula2/114520] New: Incorrect ordering of import/export statements cause confusing error messages gaius at gcc dot gnu.org
  2024-03-28 15:46 ` [Bug modula2/114520] " gaius at gcc dot gnu.org
@ 2024-03-28 16:25 ` gaius at gcc dot gnu.org
  2024-03-28 16:29 ` gaius at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-03-28 16:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114520

--- Comment #2 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Created attachment 57832
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=57832&action=edit
Proposed fix

The error recovery causes misleading error messages to appear if an EXPORT
and IMPORT statement are in the wrong order.  This patch detects the
incorrect order and issues an error message and prevents error recovery.
The fix should be improved and made more general if another similar
case is required.

gcc/m2/ChangeLog:

        * gm2-compiler/P0SyntaxCheck.bnf (DetectImport): New procedure.
        (EnableImportCheck): New boolean.
        (Expect): Call DetectImport.
        (Export): Set EnableImportCheck TRUE before ';' and FALSE
        afterwards.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug modula2/114520] Incorrect ordering of import/export statements cause confusing error messages
  2024-03-28 15:46 [Bug modula2/114520] New: Incorrect ordering of import/export statements cause confusing error messages gaius at gcc dot gnu.org
  2024-03-28 15:46 ` [Bug modula2/114520] " gaius at gcc dot gnu.org
  2024-03-28 16:25 ` gaius at gcc dot gnu.org
@ 2024-03-28 16:29 ` gaius at gcc dot gnu.org
  2024-03-28 16:50 ` cvs-commit at gcc dot gnu.org
  2024-03-28 16:52 ` gaius at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-03-28 16:29 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114520

--- Comment #3 from Gaius Mulley <gaius at gcc dot gnu.org> ---
The fix is not elegant, but it is accurate:

$ gm2 localmodule2.mod 
localmodule2.mod:13:3: error: In inner module ‘local’: an IMPORT statement must
preceed an EXPORT statement
   13 |   IMPORT mult2 ;
      |   ^~~~~~

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug modula2/114520] Incorrect ordering of import/export statements cause confusing error messages
  2024-03-28 15:46 [Bug modula2/114520] New: Incorrect ordering of import/export statements cause confusing error messages gaius at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2024-03-28 16:29 ` gaius at gcc dot gnu.org
@ 2024-03-28 16:50 ` cvs-commit at gcc dot gnu.org
  2024-03-28 16:52 ` gaius at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2024-03-28 16:50 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114520

--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Gaius Mulley <gaius@gcc.gnu.org>:

https://gcc.gnu.org/g:aeee63ffbf4f4fbc4d90d8aae808d6b67f0148a3

commit r14-9710-gaeee63ffbf4f4fbc4d90d8aae808d6b67f0148a3
Author: Gaius Mulley <gaiusmod2@gmail.com>
Date:   Thu Mar 28 16:49:44 2024 +0000

    PR modula2/114520 Incorrect ordering of import/export statements cause
confusion

    The error recovery causes misleading error messages to appear if an
    EXPORT and IMPORT statement are in the wrong order.  This patch
    detects the incorrect order and issues an error message and prevents
    error recovery.  The fix should be improved and made more general if
    another similar case is required.

    gcc/m2/ChangeLog:

            PR modula2/114520
            * gm2-compiler/P0SyntaxCheck.bnf (DetectImport): New
            procedure.
            (EnableImportCheck): New boolean.
            (Expect): Call DetectImport.
            (Export): Set EnableImportCheck TRUE before ';' and FALSE
            afterwards.

    Signed-off-by: Gaius Mulley <gaiusmod2@gmail.com>

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug modula2/114520] Incorrect ordering of import/export statements cause confusing error messages
  2024-03-28 15:46 [Bug modula2/114520] New: Incorrect ordering of import/export statements cause confusing error messages gaius at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2024-03-28 16:50 ` cvs-commit at gcc dot gnu.org
@ 2024-03-28 16:52 ` gaius at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: gaius at gcc dot gnu.org @ 2024-03-28 16:52 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114520

Gaius Mulley <gaius at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #5 from Gaius Mulley <gaius at gcc dot gnu.org> ---
Closing now that the fix has been applied.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2024-03-28 16:52 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-28 15:46 [Bug modula2/114520] New: Incorrect ordering of import/export statements cause confusing error messages gaius at gcc dot gnu.org
2024-03-28 15:46 ` [Bug modula2/114520] " gaius at gcc dot gnu.org
2024-03-28 16:25 ` gaius at gcc dot gnu.org
2024-03-28 16:29 ` gaius at gcc dot gnu.org
2024-03-28 16:50 ` cvs-commit at gcc dot gnu.org
2024-03-28 16:52 ` gaius at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).