public inbox for fortran@gcc.gnu.org
 help / color / mirror / Atom feed
* [Patch, fortran] PR fortran/96870 - Class name on error message
@ 2020-08-31 16:09 José Rui Faustino de Sousa
  2021-06-16 15:31 ` PING: " José Rui Faustino de Sousa
  0 siblings, 1 reply; 2+ messages in thread
From: José Rui Faustino de Sousa @ 2020-08-31 16:09 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 497 bytes --]

Hi all!

Proposed patch to PR96870 - Class name on error message.

Patch tested only on x86_64-pc-linux-gnu.

Make the error message more intelligible for the average user.

Thank you very much.

Best regards,
José Rui


	2020-8-21  José Rui Faustino de Sousa  <jrfsousa@gmail.com>

gcc/fortran/ChangeLog:

	PR fortran/96870
	* misc.c (gfc_typename): use class name instead of internal name
	on error message.

gcc/testsuite/ChangeLog:

	PR fortran/96870
	* gfortran.dg/PR96870.f90: New test.



[-- Attachment #2: PR96870.patch --]
[-- Type: text/x-patch, Size: 1794 bytes --]

diff --git a/gcc/fortran/misc.c b/gcc/fortran/misc.c
index 65bcfa6..43edfd8 100644
--- a/gcc/fortran/misc.c
+++ b/gcc/fortran/misc.c
@@ -184,8 +184,11 @@ gfc_typename (gfc_typespec *ts, bool for_hash)
 	  break;
 	}
       ts1 = ts->u.derived->components ? &ts->u.derived->components->ts : NULL;
-      if (ts1 && ts1->u.derived && ts1->u.derived->attr.unlimited_polymorphic)
-	sprintf (buffer, "CLASS(*)");
+      if (ts1 && ts1->u.derived)
+	if (ts1->u.derived->attr.unlimited_polymorphic)
+	  sprintf (buffer, "CLASS(*)");
+	else
+	  sprintf (buffer, "CLASS(%s)", ts1->u.derived->name);
       else
 	sprintf (buffer, "CLASS(%s)", ts->u.derived->name);
       break;
diff --git a/gcc/testsuite/gfortran.dg/PR96870.f90 b/gcc/testsuite/gfortran.dg/PR96870.f90
new file mode 100644
index 0000000..c1b321e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/PR96870.f90
@@ -0,0 +1,41 @@
+! { dg-do compile }
+!
+! Test fix for PR96870
+!
+
+Program main_p
+
+  implicit none
+  
+  Type :: t0
+  End Type t0
+  
+  Type, extends(t0) :: t1
+  End Type t1
+  
+  type(t0),   target :: x
+  class(t0), pointer :: p
+
+  p => x
+  Call sub_1(x) ! { dg-error "Type mismatch in argument .p. at .1.; passed TYPE\\(t0\\) to CLASS\\(t1\\)" }
+  Call sub_1(p) ! { dg-error "Type mismatch in argument .p. at .1.; passed CLASS\\(t0\\) to CLASS\\(t1\\)" }
+  Call sub_2(x) ! { dg-error "Type mismatch in argument .p. at .1.; passed TYPE\\(t0\\) to TYPE\\(t1\\)" }
+  Call sub_2(p) ! { dg-error "Type mismatch in argument .p. at .1.; passed CLASS\\(t0\\) to TYPE\\(t1\\)" }
+  stop
+  
+Contains
+  
+  Subroutine sub_1(p)
+    class(t1), Intent(In) :: p
+
+    return
+  End Subroutine sub_1
+  
+  Subroutine sub_2(p)
+    type(t1), Intent(In) :: p
+
+    return
+  End Subroutine sub_2
+  
+End Program main_p
+

^ permalink raw reply	[flat|nested] 2+ messages in thread

* PING: [Patch, fortran] PR fortran/96870 - Class name on error message
  2020-08-31 16:09 [Patch, fortran] PR fortran/96870 - Class name on error message José Rui Faustino de Sousa
@ 2021-06-16 15:31 ` José Rui Faustino de Sousa
  0 siblings, 0 replies; 2+ messages in thread
From: José Rui Faustino de Sousa @ 2021-06-16 15:31 UTC (permalink / raw)
  To: fortran, gcc-patches

[-- Attachment #1: Type: text/plain, Size: 759 bytes --]

*PING*


-------- Forwarded Message --------
Subject: [Patch, fortran] PR fortran/96870 - Class name on error message
Date: Mon, 31 Aug 2020 16:09:32 +0000
From: José Rui Faustino de Sousa <jrfsousa@gmail.com>
To: fortran@gcc.gnu.org, gcc-patches@gcc.gnu.org

Hi all!

Proposed patch to PR96870 - Class name on error message.

Patch tested only on x86_64-pc-linux-gnu.

Make the error message more intelligible for the average user.

Thank you very much.

Best regards,
José Rui


	2020-8-21  José Rui Faustino de Sousa  <jrfsousa@gmail.com>

gcc/fortran/ChangeLog:

	PR fortran/96870
	* misc.c (gfc_typename): use class name instead of internal name
	on error message.

gcc/testsuite/ChangeLog:

	PR fortran/96870
	* gfortran.dg/PR96870.f90: New test.




[-- Attachment #2: PR96870.patch --]
[-- Type: text/x-patch, Size: 1795 bytes --]

diff --git a/gcc/fortran/misc.c b/gcc/fortran/misc.c
index 65bcfa6..43edfd8 100644
--- a/gcc/fortran/misc.c
+++ b/gcc/fortran/misc.c
@@ -184,8 +184,11 @@ gfc_typename (gfc_typespec *ts, bool for_hash)
 	  break;
 	}
       ts1 = ts->u.derived->components ? &ts->u.derived->components->ts : NULL;
-      if (ts1 && ts1->u.derived && ts1->u.derived->attr.unlimited_polymorphic)
-	sprintf (buffer, "CLASS(*)");
+      if (ts1 && ts1->u.derived)
+	if (ts1->u.derived->attr.unlimited_polymorphic)
+	  sprintf (buffer, "CLASS(*)");
+	else
+	  sprintf (buffer, "CLASS(%s)", ts1->u.derived->name);
       else
 	sprintf (buffer, "CLASS(%s)", ts->u.derived->name);
       break;
diff --git a/gcc/testsuite/gfortran.dg/PR96870.f90 b/gcc/testsuite/gfortran.dg/PR96870.f90
new file mode 100644
index 0000000..c1b321e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/PR96870.f90
@@ -0,0 +1,41 @@
+! { dg-do compile }
+!
+! Test fix for PR96870
+!
+
+Program main_p
+
+  implicit none
+  
+  Type :: t0
+  End Type t0
+  
+  Type, extends(t0) :: t1
+  End Type t1
+  
+  type(t0),   target :: x
+  class(t0), pointer :: p
+
+  p => x
+  Call sub_1(x) ! { dg-error "Type mismatch in argument .p. at .1.; passed TYPE\\(t0\\) to CLASS\\(t1\\)" }
+  Call sub_1(p) ! { dg-error "Type mismatch in argument .p. at .1.; passed CLASS\\(t0\\) to CLASS\\(t1\\)" }
+  Call sub_2(x) ! { dg-error "Type mismatch in argument .p. at .1.; passed TYPE\\(t0\\) to TYPE\\(t1\\)" }
+  Call sub_2(p) ! { dg-error "Type mismatch in argument .p. at .1.; passed CLASS\\(t0\\) to TYPE\\(t1\\)" }
+  stop
+  
+Contains
+  
+  Subroutine sub_1(p)
+    class(t1), Intent(In) :: p
+
+    return
+  End Subroutine sub_1
+  
+  Subroutine sub_2(p)
+    type(t1), Intent(In) :: p
+
+    return
+  End Subroutine sub_2
+  
+End Program main_p
+


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-06-16 15:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-31 16:09 [Patch, fortran] PR fortran/96870 - Class name on error message José Rui Faustino de Sousa
2021-06-16 15:31 ` PING: " José Rui Faustino de Sousa

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).