[Bug fortran/56386] [F03] ICE with ASSOCIATE construct and an derived type array component

janus at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Oct 1 18:02:00 GMT 2018


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

--- Comment #7 from janus at gcc dot gnu.org ---
(In reply to Tobias Burnus from comment #2)
> Related test case by the bug reporterm
> https://groups.google.com/forum/?fromgroups=#!topic/comp.lang.fortran/
> UvBX1kfuFqs
> 
> 
> This time rejecting the code instead of ICEing:
> 
>    print *,x%i
>              1
> Error: Symbol 'x' at (1) has no IMPLICIT type

One can get past this error via:

diff --git a/gcc/fortran/primary.c b/gcc/fortran/primary.c
index 6f45afa86ea..311e3aafc85 100644
--- a/gcc/fortran/primary.c
+++ b/gcc/fortran/primary.c
@@ -2111,7 +2111,7 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag,
bool sub_flag,
          sym->ts = tgt_expr->ts;
        }

-      if (sym->ts.type == BT_UNKNOWN)
+      if (sym->ts.type == BT_UNKNOWN && !sym->assoc)
        {
          gfc_error ("Symbol %qs at %C has no IMPLICIT type", sym->name);
          return MATCH_ERROR;

but then one runs into:

7 |     print *,x%i
  |              1
Error: Syntax error in PRINT statement at (1)



> program p
>   type t
>     integer :: i = 0
>   end type
> 
>   associate (x=>f())
>     print *,x%i
>   end associate
> 
>   contains
>     function f()
>       type(t) f
>       f%i = 5
>     end function
> end program


The general problem with this case is that we can not infer the type of 'x'
before parsing the print statement. Right now I can not see how to get around
this issue.


More information about the Gcc-bugs mailing list