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

--- Comment #2 from Gaius Mulley <gaius at gcc dot gnu.org> ---
I'm not so sure the original code example is a bug, though the error message
could be improved.  Quoting ISO standard P.42

"""
Note - In the case of an import list appearing in a local module, the
given environment is the environment that applies at the point of the
local module declaration - see 6.2.12.  In the case of an import list
appearing in a program module, definition module, or implementation
module, the given environment is the outermost environment which
includes the identifiers of the system modules and the separate modules
of the program.
"""

Unless I've misunderstood the above it seems that in the case of a local
module "IMPORT sym".  sym cannot refer to a definition module.

Assuming this is correct I'll add a error message/hint (if sym matches a
definition module).


To summarise:

$ cat tinygoodimport.mod

MODULE tinygoodimport ;

IMPORT ASCII ;

   MODULE inner ;
   IMPORT ASCII ;
   VAR
      foo: CHAR ;
   BEGIN
      foo := ASCII.nul
   END inner ;

BEGIN
END tinygoodimport.


$ gm2 tinygoodimport.mod
tinygoodimport.mod:10:14: error: In inner module ‘inner’: ‘ASCII’ looks like a
module which has not been globally imported (eg. suggest that you IMPORT
‘ASCII’
   10 |       foo := ASCII.nul
      |              ^~~~~

(it should have compiled without error).


$ cat tinybadimport.mod
MODULE tinybadimport ;

   MODULE inner ;
   IMPORT ASCII ;
   VAR
      foo: CHAR ;
   BEGIN
      foo := ASCII.nul ;
   END inner ;

BEGIN
END tinybadimport.

$ gm2 tinybadimport.mod
tinybadimport.mod:4:11: error: In inner module ‘inner’: unknown symbol ‘ASCII’ 
    4 |    IMPORT ASCII ;
      |           ^~~~~

which is correct.

Reply via email to