Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Semantics / stmt-func01.f90
blob0f4fed51c1184d934a4a9868af8307aa42528622
1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 ! C1577
3 program main
4 type t1(k,l)
5 integer, kind :: k = kind(1)
6 integer, len :: l = 666
7 integer(k) n
8 end type t1
9 interface
10 pure integer function ifunc()
11 end function
12 end interface
13 type(t1(k=4,l=ifunc())) x1
14 !PORTABILITY: Statement function 'sf1' should not contain an array constructor
15 sf1(n) = sum([(j,j=1,n)])
16 type(t1) sf2
17 !PORTABILITY: Statement function 'sf2' should not contain a structure constructor
18 sf2(n) = t1(n)
19 !PORTABILITY: Statement function 'sf3' should not contain a type parameter inquiry
20 sf3(n) = x1%l
21 !ERROR: Recursive call to statement function 'sf4' is not allowed
22 sf4(n) = sf4(n)
23 !ERROR: Statement function 'sf5' may not reference another statement function 'sf6' that is defined later
24 sf5(n) = sf6(n)
25 real sf7
26 !ERROR: Statement function 'sf6' may not reference another statement function 'sf7' that is defined later
27 sf6(n) = sf7(n)
28 !PORTABILITY: Statement function 'sf7' should not reference function 'explicit' that requires an explicit interface
29 sf7(n) = explicit(n)
30 real :: a(3) = [1., 2., 3.]
31 !PORTABILITY: Statement function 'sf8' should not pass an array argument that is not a whole array
32 sf8(n) = sum(a(1:2))
33 sf8a(n) = sum(a) ! ok
34 integer :: sf9
35 !ERROR: Defining expression of statement function 'sf9' cannot be converted to its result type INTEGER(4)
36 sf9(n) = "bad"
37 sf10 = 1.
38 contains
39 real function explicit(x,y)
40 integer, intent(in) :: x
41 integer, intent(in), optional :: y
42 explicit = x
43 end function
44 pure function arr()
45 real :: arr(2)
46 arr = [1., 2.]
47 end function
48 subroutine foo
49 !PORTABILITY: An implicitly typed statement function should not appear when the same symbol is available in its host scope
50 sf10(x) = 2.*x
51 end subroutine
52 end