summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gfortran.dg/associate_9.f03
blob: 13a10fc0d9c6ecf3e2026b03dab38bfb56bf5aec (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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" } }