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.

Reply via email to