diff mbox

pr59016

Message ID 55250310.50201@sfr.fr
State New
Headers show

Commit Message

Mikael Morin April 8, 2015, 10:29 a.m. UTC
Le 07/04/2015 14:25, Mikael Morin a écrit :
> Le 06/04/2015 20:26, Mikael Morin a écrit :
>> Regarding the patch, I don't understand why the existing symbol
>> restoration code doesn't work here (see
>> gfc_restore_last_undo_checkpoint, restore_old_symbol).  I have to
>> investigate more.
> 
> I think the problem is the usage of gfc_find_symbol in
> gfc_match_decl_type_spec.
> In opposition to the gfc_get_* family of functions, the gfc_find_*
> functions don't version symbols, so that changes made to the symbol are
> not thrown away when the statement is rejected.
> 
So something like the following should be preferred over Evangelos' patch.
Except that the following ... ahem ... doesn't work.

Mikael

Comments

Mikael Morin April 8, 2015, 11:26 a.m. UTC | #1
Le 08/04/2015 12:29, Mikael Morin a écrit :
> Except that the following ... ahem ... doesn't work.
> 
And it doesn't work because gfc_get_ha_symbol doesn't version
host-associated symbols.
So one has to call symbol.c's save_symbol_data by hand.  And then, we
can as well keep the original gfc_find_symbol calls.
Evangelos, do you want to propose a patch along those lines?

Mikael
diff mbox

Patch

Index: decl.c
===================================================================
--- decl.c	(révision 221654)
+++ decl.c	(copie de travail)
@@ -2840,7 +2840,7 @@  gfc_match_decl_type_spec (gfc_typespec *ts, int im
   if (ts->kind != -1)
     {
       gfc_get_ha_symbol (name, &sym);
-      if (sym->generic && gfc_find_symbol (dt_name, NULL, 0, &dt_sym))
+      if (sym->generic && gfc_get_symbol (dt_name, NULL, &dt_sym))
 	{
 	  gfc_error ("Type name %qs at %C is ambiguous", name);
 	  return MATCH_ERROR;
@@ -2850,10 +2850,11 @@  gfc_match_decl_type_spec (gfc_typespec *ts, int im
     }
   else if (ts->kind == -1)
     {
-      int iface = gfc_state_stack->previous->state != COMP_INTERFACE
-		    || gfc_current_ns->has_import_set;
-      gfc_find_symbol (name, NULL, iface, &sym);
-      if (sym && sym->generic && gfc_find_symbol (dt_name, NULL, 1, &dt_sym))
+      gfc_get_ha_symbol (name, &sym);
+      if (sym == NULL || sym->gfc_new)
+	return MATCH_NO;
+
+      if (sym && sym->generic && gfc_get_ha_symbol (dt_name, &dt_sym))
 	{
 	  gfc_error ("Type name %qs at %C is ambiguous", name);
 	  return MATCH_ERROR;
@@ -2862,8 +2863,6 @@  gfc_match_decl_type_spec (gfc_typespec *ts, int im
 	dt_sym = gfc_find_dt_in_generic (sym);
 
       ts->kind = 0;
-      if (sym == NULL)
-	return MATCH_NO;
     }
 
   if ((sym->attr.flavor != FL_UNKNOWN
@@ -2885,12 +2884,13 @@  gfc_match_decl_type_spec (gfc_typespec *ts, int im
       && !gfc_add_function (&sym->attr, sym->name, NULL))
     return MATCH_ERROR;
 
-  if (!dt_sym)
+  if (!dt_sym || dt_sym->gfc_new)
     {
       gfc_interface *intr, *head;
 
       /* Use upper case to save the actual derived-type symbol.  */
-      gfc_get_symbol (dt_name, NULL, &dt_sym);
+      if (!dt_sym)
+	gfc_get_symbol (dt_name, NULL, &dt_sym);
       dt_sym->name = gfc_get_string (sym->name);
       head = sym->generic;
       intr = gfc_get_interface ();