From a81f4b678524dbc3c3614f785c5bfee0944ce522 Mon Sep 17 00:00:00 2001 From: Daniel Kraft Date: Tue, 12 Oct 2010 15:30:53 +0200 Subject: [PATCH] re PR fortran/38936 ([F03] ASSOCIATE construct / improved SELECT TYPE (a=>expr)) 2010-10-12 Daniel Kraft PR fortran/38936 * parse.c (parse_associate): Set typespec of associate-name if that of the target is already available. 2010-10-12 Daniel Kraft PR fortran/38936 * gfortran.dg/associate_1.f03: More tests with derived-types. * gfortran.dg/associate_9.f03: New test (XFAIL for now). * gfortran.dg/associate_8.f03: Fix typo. * gfortran.dg/initialization_27.f90: Fix typo. From-SVN: r165378 --- gcc/fortran/ChangeLog | 6 +++ gcc/fortran/parse.c | 7 +++ gcc/testsuite/ChangeLog | 8 +++ gcc/testsuite/gfortran.dg/associate_1.f03 | 3 +- gcc/testsuite/gfortran.dg/associate_8.f03 | 2 +- gcc/testsuite/gfortran.dg/associate_9.f03 | 51 +++++++++++++++++++ .../gfortran.dg/initialization_27.f90 | 2 +- 7 files changed, 76 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gfortran.dg/associate_9.f03 diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index f748da633e3..517b50096d5 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,9 @@ +2010-10-12 Daniel Kraft + + PR fortran/38936 + * parse.c (parse_associate): Set typespec of associate-name if that of + the target is already available. + 2010-10-10 Janus Weil PR fortran/45961 diff --git a/gcc/fortran/parse.c b/gcc/fortran/parse.c index 268e6afc049..89ffbafa96c 100644 --- a/gcc/fortran/parse.c +++ b/gcc/fortran/parse.c @@ -3237,6 +3237,13 @@ parse_associate (void) sym->assoc = a; sym->declared_at = a->where; gfc_set_sym_referenced (sym); + + /* Initialize the typespec. It is not available in all cases, + however, as it may only be set on the target during resolution. + Still, sometimes it helps to have it right now -- especially + for parsing component references on the associate-name + in case of assication to a derived-type. */ + sym->ts = a->target->ts; } accept_statement (ST_ASSOCIATE); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5b7c05441a3..a87da8cf71a 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,11 @@ +2010-10-12 Daniel Kraft + + PR fortran/38936 + * gfortran.dg/associate_1.f03: More tests with derived-types. + * gfortran.dg/associate_9.f03: New test (XFAIL for now). + * gfortran.dg/associate_8.f03: Fix typo. + * gfortran.dg/initialization_27.f90: Fix typo. + 2010-10-12 Rainer Orth PR testsuite/45851 diff --git a/gcc/testsuite/gfortran.dg/associate_1.f03 b/gcc/testsuite/gfortran.dg/associate_1.f03 index 4cb727f0b5a..d7b14aebeb5 100644 --- a/gcc/testsuite/gfortran.dg/associate_1.f03 +++ b/gcc/testsuite/gfortran.dg/associate_1.f03 @@ -76,9 +76,10 @@ PROGRAM main ! Association to derived type and component. tp = myt (1) ASSOCIATE (x => tp, y => tp%comp) - ! FIXME: Parsing of derived-type associate names, tests with x. + IF (x%comp /= 1) CALL abort () IF (y /= 1) CALL abort () y = 5 + IF (x%comp /= 5) CALL abort () END ASSOCIATE IF (tp%comp /= 5) CALL abort () diff --git a/gcc/testsuite/gfortran.dg/associate_8.f03 b/gcc/testsuite/gfortran.dg/associate_8.f03 index 0c95acb8c2b..a6f9938f0bb 100644 --- a/gcc/testsuite/gfortran.dg/associate_8.f03 +++ b/gcc/testsuite/gfortran.dg/associate_8.f03 @@ -1,4 +1,4 @@ -! { dg-do run} +! { dg-do run } ! { dg-options "-std=f2003 -fall-intrinsics" } ! PR fortran/38936 diff --git a/gcc/testsuite/gfortran.dg/associate_9.f03 b/gcc/testsuite/gfortran.dg/associate_9.f03 new file mode 100644 index 00000000000..13a10fc0d9c --- /dev/null +++ b/gcc/testsuite/gfortran.dg/associate_9.f03 @@ -0,0 +1,51 @@ +! { dg-do compile } +! { dg-options "-std=f2003 -fall-intrinsics" } + +! FIXME: Change into run test and remove excess error expectation. + +! PR fortran/38936 +! Association to derived-type, where the target type is not know +! during parsing (only resolution). + +! Contributed by Daniel Kraft, d@domob.eu. + +MODULE m + IMPLICIT NONE + + TYPE :: mynum + INTEGER :: comp + END TYPE mynum + + INTERFACE OPERATOR(+) + MODULE PROCEDURE add + END INTERFACE OPERATOR(+) + +CONTAINS + + PURE FUNCTION add (a, b) + TYPE(mynum), INTENT(IN) :: a, b + TYPE(mynum) :: add + + add%comp = a%comp + b%comp + END FUNCTION add + +END MODULE m + +PROGRAM main + USE :: m + IMPLICIT NONE + + TYPE(mynum) :: a + a = mynum (5) + + ASSOCIATE (x => add (a, a)) + IF (x%comp /= 10) CALL abort () + END ASSOCIATE + + ASSOCIATE (x => a + a) + IF (x%comp /= 10) CALL abort () + END ASSOCIATE +END PROGRAM main + +! { dg-excess-errors "Syntex error in IF" } +! { dg-final { cleanup-modules "m" } } diff --git a/gcc/testsuite/gfortran.dg/initialization_27.f90 b/gcc/testsuite/gfortran.dg/initialization_27.f90 index 680a457e8f1..8e21936f6f9 100644 --- a/gcc/testsuite/gfortran.dg/initialization_27.f90 +++ b/gcc/testsuite/gfortran.dg/initialization_27.f90 @@ -1,4 +1,4 @@ -! { dg-do run} +! { dg-do run } ! ! PR fortran/45489 !