Skip to content

Commit 9684e70

Browse files
author
Andre Vehreschild
committed
Fortran: Fix associate with derived type array construtor [PR117347]
gcc/fortran/ChangeLog: PR fortran/117347 * primary.cc (gfc_match_varspec): Add array constructors for guessing their type like with unresolved function calls. gcc/testsuite/ChangeLog: * gfortran.dg/associate_71.f90: New test.
1 parent 733edbf commit 9684e70

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

gcc/fortran/primary.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2423,6 +2423,7 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag,
24232423
component name 're' or 'im' could be found. */
24242424
if (tgt_expr
24252425
&& (tgt_expr->expr_type == EXPR_FUNCTION
2426+
|| tgt_expr->expr_type == EXPR_ARRAY
24262427
|| (!resolved && tgt_expr->expr_type == EXPR_OP))
24272428
&& (sym->ts.type == BT_UNKNOWN
24282429
|| (inferred_type && sym->ts.type != BT_COMPLEX))
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
! { dg-do run }
2+
!
3+
! Check that pr117347 is fixed.
4+
! Contributed by Ivan Pribec <[email protected]>
5+
6+
program pr117347
7+
implicit none
8+
9+
type :: point
10+
real :: x = 42.
11+
end type point
12+
13+
type(point) :: mypoint
14+
real :: pi(1)
15+
associate (points => mypoint )
16+
pi(:) = points% x
17+
end associate
18+
if (any(pi /= 42)) stop 1
19+
associate (points => (mypoint))
20+
pi(:) = points% x
21+
end associate
22+
if (any(pi /= 42)) stop 2
23+
associate (points => [mypoint])
24+
pi(:) = points% x
25+
end associate
26+
if (any(pi /= 42)) stop 3
27+
associate (points => [rpoint()])
28+
pi(:) = points% x
29+
end associate
30+
if (any(pi /= 35)) stop 4
31+
32+
contains
33+
34+
function rpoint() result(r)
35+
type(point) :: r
36+
r%x = 35
37+
end function
38+
end program
39+

0 commit comments

Comments
 (0)