1! RUN: %S/test_errors.sh %s %t %f18
2integer :: y
3procedure() :: a
4procedure(real) :: b
5call a  ! OK - can be function or subroutine
6!ERROR: Cannot call subroutine 'a' like a function
7c = a()
8!ERROR: Cannot call function 'b' like a subroutine
9call b
10!ERROR: Cannot call function 'y' like a subroutine
11call y
12call x
13!ERROR: Cannot call subroutine 'x' like a function
14z = x()
15end
16
17subroutine s
18  !ERROR: Cannot call function 'f' like a subroutine
19  call f
20  !ERROR: Cannot call subroutine 's' like a function
21  i = s()
22contains
23  function f()
24  end
25end
26
27subroutine s2
28  ! subroutine vs. function is determined by use
29  external :: a, b
30  call a()
31  !ERROR: Cannot call subroutine 'a' like a function
32  x = a()
33  x = b()
34  !ERROR: Cannot call function 'b' like a subroutine
35  call b()
36end
37
38subroutine s3
39  ! subroutine vs. function is determined by use, even in internal subprograms
40  external :: a
41  procedure() :: b
42contains
43  subroutine s3a()
44    x = a()
45    call b()
46  end
47  subroutine s3b()
48    !ERROR: Cannot call function 'a' like a subroutine
49    call a()
50    !ERROR: Cannot call subroutine 'b' like a function
51    x = b()
52  end
53end
54
55module m
56  ! subroutine vs. function is determined at end of specification part
57  external :: a
58  procedure() :: b
59contains
60  subroutine s()
61    call a()
62    !ERROR: Cannot call subroutine 'b' like a function
63    x = b()
64  end
65end
66
67! Call to entity in global scope, even with IMPORT, NONE
68subroutine s4
69  block
70    import, none
71    integer :: i
72    !ERROR: Use of 'm' as a procedure conflicts with its declaration
73    i = m()
74    !ERROR: Use of 'm' as a procedure conflicts with its declaration
75    call m()
76  end block
77end
78
79! Call to entity in global scope, even with IMPORT, NONE
80subroutine s5
81  block
82    import, none
83    integer :: i
84    i = foo()
85    !ERROR: Cannot call function 'foo' like a subroutine
86    call foo()
87  end block
88end
89
90subroutine s6
91  call a6()
92end
93!ERROR: 'a6' was previously called as a subroutine
94function a6()
95  a6 = 0.0
96end
97
98subroutine s7
99  x = a7()
100end
101!ERROR: 'a7' was previously called as a function
102subroutine a7()
103end
104
105!OK: use of a8 and b8 is consistent
106subroutine s8
107  call a8()
108  x = b8()
109end
110subroutine a8()
111end
112function b8()
113  b8 = 0.0
114end
115