Skip to content

Commit

Permalink
Fortran: Fix associate with derived type array construtor [PR117347]
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Andre Vehreschild committed Dec 17, 2024
1 parent 733edbf commit 9684e70
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions gcc/fortran/primary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2423,6 +2423,7 @@ gfc_match_varspec (gfc_expr *primary, int equiv_flag, bool sub_flag,
component name 're' or 'im' could be found. */
if (tgt_expr
&& (tgt_expr->expr_type == EXPR_FUNCTION
|| tgt_expr->expr_type == EXPR_ARRAY
|| (!resolved && tgt_expr->expr_type == EXPR_OP))
&& (sym->ts.type == BT_UNKNOWN
|| (inferred_type && sym->ts.type != BT_COMPLEX))
Expand Down
39 changes: 39 additions & 0 deletions gcc/testsuite/gfortran.dg/associate_71.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
! { dg-do run }
!
! Check that pr117347 is fixed.
! Contributed by Ivan Pribec <[email protected]>

program pr117347
implicit none

type :: point
real :: x = 42.
end type point

type(point) :: mypoint
real :: pi(1)
associate (points => mypoint )
pi(:) = points% x
end associate
if (any(pi /= 42)) stop 1
associate (points => (mypoint))
pi(:) = points% x
end associate
if (any(pi /= 42)) stop 2
associate (points => [mypoint])
pi(:) = points% x
end associate
if (any(pi /= 42)) stop 3
associate (points => [rpoint()])
pi(:) = points% x
end associate
if (any(pi /= 35)) stop 4

contains

function rpoint() result(r)
type(point) :: r
r%x = 35
end function
end program

0 comments on commit 9684e70

Please sign in to comment.