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