http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51945

--- Comment #4 from janus at gcc dot gnu.org ---
The following patch should somewhat improve the situation:


Index: gcc/fortran/resolve.c
===================================================================
--- gcc/fortran/resolve.c    (revision 201576)
+++ gcc/fortran/resolve.c    (working copy)
@@ -1178,7 +1178,7 @@ resolve_structure_cons (gfc_expr *expr, int init)
              gfc_basic_typename (comp->ts.type));
           t = false;
         }
-      else
+      else if (!init)
         {
           bool t2 = gfc_convert_type (cons->expr, &comp->ts, 1);
           if (t)
@@ -12344,7 +12344,7 @@ resolve_fl_derived0 (gfc_symbol *sym)

       if (c->initializer && !sym->attr.vtype
       && !gfc_check_assign_symbol (sym, c, c->initializer))
-    return false;
+    continue;
     }

   check_defined_assignments (sym);



The first hunk suppresses the errors in the resolution of the symbol 'a', since
they should already be thrown in the resolution of the type.

The second hunk makes sure one gets the error in both components when resolving
the type (a similar thing is also done in PR 58023 comment 5).


With the above patch I get the expected result on the original test case in
comment 0:

Error: Can't convert TYPE(t2) to TYPE(t) at (1)
Error: Can't convert TYPE(t3) to TYPE(t) at (1)

On the version with the uncommented line, each error unfortunately still
appears twice, but that is due to the fact that the type symbol is resolved
twice (cf. also PR 44978).

Reply via email to