1! { dg-do run }
2!
3! PR fortran/39427
4!
5module foo_module
6  interface foo
7    procedure constructor
8  end interface
9
10  type foo
11    integer :: bar
12  end type
13contains
14  type(foo) function constructor()
15    constructor%bar = 1
16  end function
17
18  subroutine test_foo()
19    type(foo) :: f
20    f = foo()
21    if (f%bar /= 1) call abort ()
22    f = foo(2)
23    if (f%bar /= 2) call abort ()
24  end subroutine test_foo
25end module foo_module
26
27
28! Same as foo_module but order
29! of INTERFACE and TYPE reversed
30module bar_module
31  type bar
32    integer :: bar
33  end type
34
35  interface bar
36    procedure constructor
37  end interface
38contains
39  type(bar) function constructor()
40    constructor%bar = 3
41  end function
42
43  subroutine test_bar()
44    type(bar) :: f
45    f = bar()
46    if (f%bar /= 3) call abort ()
47    f = bar(4)
48    if (f%bar /= 4) call abort ()
49  end subroutine test_bar
50end module bar_module
51
52program main
53  use foo_module
54  use bar_module
55  implicit none
56
57  type(foo) :: f
58  type(bar) :: b
59
60  call test_foo()
61  f = foo()
62  if (f%bar /= 1) call abort ()
63  f = foo(2)
64  if (f%bar /= 2) call abort ()
65
66  call test_bar()
67  b = bar()
68  if (b%bar /= 3) call abort ()
69  b = bar(4)
70  if (b%bar /= 4) call abort ()
71end program main
72
73! { dg-final { cleanup-tree-dump "foo_module bar_module" } }
74