User account creation filtered due to spam.

Bug 50252 - [OOP] Error message on "call x%y" (x not declared) can be more informative
Summary: [OOP] Error message on "call x%y" (x not declared) can be more informative
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.6.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-08-31 14:14 UTC by Arjen Markus
Modified: 2014-01-07 08:15 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-01-07 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Arjen Markus 2011-08-31 14:14:49 UTC
If you forget to declare a variable with type-bound procedures, say x,
and call one of the intended procedures anyway, the message is simply
that there was a syntax error.

The program:


program test123

    call bb%print

end program test123


results in the following error message:


xx.f90:3.11:

    call x%print
           1
Error: Syntax error in CALL statement at (1)

This message could be made clearer by pointing out that a variable
may not be declared - if the statement contains a %:

Error: Syntax error in CALL statement at (1). Possibly a variable has not been declared.
Comment 1 janus 2011-08-31 19:03:39 UTC
The parsing of call statements happens in gfc_match_call (match.c), so any improvement of the error message will most likely have to happen there.
Comment 2 janus 2011-08-31 19:31:10 UTC
Ok, here is one thing that could be easily done. Preliminary patch, not regtested. Does this sound like an improvement?


Index: gcc/fortran/match.c
===================================================================
--- gcc/fortran/match.c (revision 178293)
+++ gcc/fortran/match.c (working copy)
@@ -3639,15 +3639,24 @@ done:
 }
 
 
-/* Match the call of a type-bound procedure, if CALL%var has already been 
-   matched and var found to be a derived-type variable.  */
+/* Match the call of a type-bound procedure, if 'CALL var' has already been 
+   matched.  */
 
 static match
 match_typebound_call (gfc_symtree* varst)
 {
   gfc_expr* base;
+  gfc_symbol *sym;
   match m;
 
+  sym = varst->n.sym;
+  if (sym->ts.type != BT_DERIVED && sym->ts.type != BT_CLASS)
+    {
+      gfc_error ("Base object '%s' in type-bound procedure call at %C "
+                "is not of derived type", sym->name);
+      return MATCH_ERROR;
+    }
+    
   base = gfc_get_expr ();
   base->expr_type = EXPR_VARIABLE;
   base->symtree = varst;
@@ -3718,7 +3727,7 @@ gfc_match_call (void)
      procedure call.  */
   if ((sym->attr.flavor != FL_PROCEDURE
        || gfc_is_function_return_value (sym, gfc_current_ns))
-      && (sym->ts.type == BT_DERIVED || sym->ts.type == BT_CLASS))
+      && gfc_peek_char() == '%')
     return match_typebound_call (st);
 
   /* If it does not seem to be callable (include functions so that the
Comment 3 Arjen Markus 2011-09-01 07:18:30 UTC
Hi Janus,

that seems quite to the point and it is much more straightforward than
my (minimal)
adjustment. Thanks.

The reason I brought this is that is a fairly recent addition and I
got puzzled by the
complaint that it was a syntax error.

Regards,

Arjen

2011/8/31 janus at gcc dot gnu.org <gcc-bugzilla@gcc.gnu.org>:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50252
>
> --- Comment #2 from janus at gcc dot gnu.org 2011-08-31 19:31:10 UTC ---
> Ok, here is one thing that could be easily done. Preliminary patch, not
> regtested. Does this sound like an improvement?
>
>
> Index: gcc/fortran/match.c
> ===================================================================
> --- gcc/fortran/match.c (revision 178293)
> +++ gcc/fortran/match.c (working copy)
> @@ -3639,15 +3639,24 @@ done:
>  }
>
>
> -/* Match the call of a type-bound procedure, if CALL%var has already been
> -   matched and var found to be a derived-type variable.  */
> +/* Match the call of a type-bound procedure, if 'CALL var' has already been
> +   matched.  */
>
>  static match
>  match_typebound_call (gfc_symtree* varst)
>  {
>   gfc_expr* base;
> +  gfc_symbol *sym;
>   match m;
>
> +  sym = varst->n.sym;
> +  if (sym->ts.type != BT_DERIVED && sym->ts.type != BT_CLASS)
> +    {
> +      gfc_error ("Base object '%s' in type-bound procedure call at %C "
> +                "is not of derived type", sym->name);
> +      return MATCH_ERROR;
> +    }
> +
>   base = gfc_get_expr ();
>   base->expr_type = EXPR_VARIABLE;
>   base->symtree = varst;
> @@ -3718,7 +3727,7 @@ gfc_match_call (void)
>      procedure call.  */
>   if ((sym->attr.flavor != FL_PROCEDURE
>        || gfc_is_function_return_value (sym, gfc_current_ns))
> -      && (sym->ts.type == BT_DERIVED || sym->ts.type == BT_CLASS))
> +      && gfc_peek_char() == '%')
>     return match_typebound_call (st);
>
>   /* If it does not seem to be callable (include functions so that the
>
> --
> Configure bugmail: http://gcc.gnu.org/bugzilla/userprefs.cgi?tab=email
> ------- You are receiving this mail because: -------
> You reported the bug.
>
Comment 4 janus 2011-09-01 11:28:35 UTC
Unfortunately the patch in comment #2 did not survive the regression test. It fails at least on:

FAIL: gfortran.dg/dynamic_dispatch_10.f03  -O0  (test for excess errors)
FAIL: gfortran.dg/coarray_14.f90  -O   (test for errors, line 39)
FAIL: gfortran.dg/coarray_8.f90  -O   (test for errors, line 36)
FAIL: gfortran.dg/proc_ptr_comp_pass_6.f90  -O  (test for excess errors)
FAIL: gfortran.dg/typebound_call_12.f03  -O  (test for excess errors)
FAIL: gfortran.dg/typebound_call_14.f03  -O  (test for excess errors)
FAIL: gfortran.dg/typebound_call_4.f03  -O   (test for errors, line 41)
Comment 5 Dominique d'Humieres 2014-01-07 08:15:35 UTC
Still present at r206382.