Hello world,

the attached patch fixes the regression of PR 60526 by checking for
the presence of a type with the same name as the variable.  Types
effectively have their separate namespace because the names of their
symtrees start with an uppercase letter.  So far, so good.

However, the error message generated is far to big, and contains
statements which are not relevant and also empty lines.

For the test case

type xx
end type

integer :: q
real :: a
integer, parameter :: h=3

type(xX) :: Xx

end


the error message becomes

type3.f90:8:14:

 type xx
       2
 end type



 integer :: q

 real :: a

 integer, parameter :: h=3



 type(xX) :: Xx
              1
Error: Symbol »xx« at (1) also declared as a type at (2)

The error message is emitted via

      gfc_error ("Symbol %qs at %C also declared as a type at %L", name,
                &st->n.sym->declared_at);

which I think is the right thing to do.  Am I using this wrong, or is it
a quirk in gfc_error or in the general error handling routines?

Regards

        Thomas
Index: decl.c
===================================================================
--- decl.c	(Revision 232864)
+++ decl.c	(Arbeitskopie)
@@ -1215,10 +1215,32 @@ build_sym (const char *name, gfc_charlen *cl, bool
 {
   symbol_attribute attr;
   gfc_symbol *sym;
+  char *u_name;
+  int nlen;
+  gfc_symtree *st;
 
   if (gfc_get_symbol (name, NULL, &sym))
     return false;
 
+  /* Check if the name has already been defined as a type.  The
+     first letter of the symtree will be in upper case then.  */
+
+  nlen = strlen(name);
+
+  u_name = XCNEWVEC(char, nlen+1);
+  u_name[0] = TOUPPER(name[0]);
+  strncpy (u_name+1, name+1, nlen);
+
+  st = gfc_find_symtree (gfc_current_ns->sym_root, u_name);
+  free (u_name);
+
+  if (st != 0)
+    {
+      gfc_error ("Symbol %qs at %C also declared as a type at %L", name,
+		 &st->n.sym->declared_at);
+      return false;
+    }
+
   /* Start updating the symbol table.  Add basic type attribute if present.  */
   if (current_ts.type != BT_UNKNOWN
       && (sym->attr.implicit_type == 0

Reply via email to