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

commit r16-6221-ge9b35866f564890255b864e960eda4b3c10372ef
Author: Gaius Mulley <[email protected]>
Date:   Wed Dec 17 17:02:09 2025 +0000

    PR modula2/23178: reduce error message clutter when reporting a non 
procedure
    
    This bug fix corrects the token of an error message when reporting
    about a symbol which was not exported from a definition module.
    The reimplemented procedure CheckCanBeImported uses MetaError2
    with the spell hint format specifier if the symbol is unknown
    rather than the older WriteFormat2 procedure.
    
    gcc/m2/ChangeLog:
    
            PR modula2/23178
            * gm2-compiler/P3SymBuild.mod (CheckCanBeImported): Reimplement to
            use MetaError2 and provide spell hints if possible for unknown 
symbols.
    
    gcc/testsuite/ChangeLog:
    
            PR modula2/23178
            * gm2/pim/fail/badprocedure.mod: New test.
    
    Signed-off-by: Gaius Mulley <[email protected]>

Diff:
---
 gcc/m2/gm2-compiler/P3SymBuild.mod          | 31 +++++++++++++++++------------
 gcc/testsuite/gm2/pim/fail/badprocedure.mod |  7 +++++++
 2 files changed, 25 insertions(+), 13 deletions(-)

diff --git a/gcc/m2/gm2-compiler/P3SymBuild.mod 
b/gcc/m2/gm2-compiler/P3SymBuild.mod
index 8d8e12f771c4..7ab421c39db5 100644
--- a/gcc/m2/gm2-compiler/P3SymBuild.mod
+++ b/gcc/m2/gm2-compiler/P3SymBuild.mod
@@ -35,6 +35,7 @@ FROM SymbolTable IMPORT NulSym, ModeOfAddr, ProcedureKind,
                         SetCurrentModule, GetCurrentModule, SetFileModule,
                         GetExported, IsExported, IsImplicityExported,
                         IsDefImp, IsModule, IsImported, IsIncludedByDefinition,
+                        IsUnknown,
                         RequestSym,
                         IsProcedure, PutOptArgInit,
                         IsFieldEnumeration, GetType,
@@ -62,6 +63,7 @@ FROM M2Comp IMPORT CompilingDefinitionModule,
 
 FROM FifoQueue IMPORT GetSubrangeFromFifoQueue ;
 FROM M2Reserved IMPORT NulTok, ImportTok ;
+FROM M2MetaError IMPORT MetaError2 ;
 
 IMPORT M2Error ;
 IMPORT M2StackSpell ;
@@ -419,32 +421,35 @@ END CheckImportListOuterModule ;
 
 
 (*
-   CheckCanBeImported - checks to see that it is legal to import, Sym, from, 
ModSym.
+   CheckCanBeImported - checks to see that it is legal to import Sym from 
ModSym.
 *)
 
 PROCEDURE CheckCanBeImported (ModSym, Sym: CARDINAL) ;
-VAR
-   n1, n2: Name ;
 BEGIN
-   IF IsDefImp(ModSym)
+   IF IsDefImp (ModSym)
    THEN
-      IF IsExported(ModSym, Sym)
+      IF IsExported (ModSym, Sym)
       THEN
-         (* great all done *)
+         (* All done.  *)
          RETURN
       ELSE
-         IF IsImplicityExported(ModSym, Sym)
+         IF IsImplicityExported (ModSym, Sym)
          THEN
-            (* this is also legal *)
+            (* This is also legal.  *)
             RETURN
-         ELSIF IsDefImp(Sym) AND IsIncludedByDefinition(ModSym, Sym)
+         ELSIF IsDefImp (Sym) AND IsIncludedByDefinition (ModSym, Sym)
          THEN
-            (* this is also legal (for a definition module) *)
+            (* This is also legal (for a definition module).  *)
             RETURN
          END ;
-         n1 := GetSymName(ModSym) ;
-         n2 := GetSymName(Sym) ;
-         WriteFormat2('symbol %a is not exported from definition module %a', 
n2, n1)
+         (* Use spell checker for Unknown symbols.  *)
+         IF IsUnknown (Sym)
+         THEN
+            (* Spellcheck.  *)
+            MetaError2 ('{%1Ua} is not exported from definition module {%2a} 
{%1&s}', Sym, ModSym)
+         ELSE
+            MetaError2 ('{%1Ua} is not exported from definition module {%2a}', 
Sym, ModSym)
+         END
       END
    END
 END CheckCanBeImported ;
diff --git a/gcc/testsuite/gm2/pim/fail/badprocedure.mod 
b/gcc/testsuite/gm2/pim/fail/badprocedure.mod
new file mode 100644
index 000000000000..9b59dbded499
--- /dev/null
+++ b/gcc/testsuite/gm2/pim/fail/badprocedure.mod
@@ -0,0 +1,7 @@
+MODULE badprocedure ;
+
+IMPORT FIO ;
+
+BEGIN
+   FIO.WriteLn (FIO.StdOut)
+END badprocedure.

Reply via email to