xref: /llvm-project/flang/test/Semantics/expr-errors02.f90 (revision 338f21a4bd6b43d9a2eb00929d24cefeb0ccf581)
1! RUN: %python %S/test_errors.py %s %flang_fc1
2! Test specification expressions
3
4module m
5  type :: t(n)
6    integer, len :: n = 1
7    character(len=n) :: c
8  end type
9  interface
10    integer function foo()
11    end function
12    pure real function realfunc(x)
13      real, intent(in) :: x
14    end function
15    pure integer function hasProcArg(p)
16      import realfunc
17      procedure(realfunc) :: p
18      optional :: p
19    end function
20  end interface
21  integer :: coarray[*]
22 contains
23  pure integer function modulefunc1(n)
24    integer, value :: n
25    modulefunc1 = n
26  end function
27  subroutine test(out, optional)
28    !ERROR: Invalid specification expression: reference to impure function 'foo'
29    type(t(foo())) :: x1
30    integer :: local
31    !ERROR: Invalid specification expression: reference to local entity 'local'
32    type(t(local)) :: x2
33    !ERROR: The internal function 'internal' may not be referenced in a specification expression
34    type(t(internal(0))) :: x3
35    integer, intent(out) :: out
36    !ERROR: Invalid specification expression: reference to INTENT(OUT) dummy argument 'out'
37    type(t(out)) :: x4
38    integer, intent(in), optional :: optional
39    !ERROR: Invalid specification expression: reference to OPTIONAL dummy argument 'optional'
40    type(t(optional)) :: x5
41    !ERROR: Invalid specification expression: reference to function 'hasprocarg' with dummy procedure argument 'p'
42    type(t(hasProcArg())) :: x6
43    !ERROR: Invalid specification expression: coindexed reference
44    type(t(coarray[1])) :: x7
45    type(t(kind(foo()))) :: x101 ! ok
46    type(t(modulefunc1(0))) :: x102 ! ok
47    type(t(modulefunc2(0))) :: x103 ! ok
48   contains
49    pure integer function internal(n)
50      integer, value :: n
51      internal = n
52    end function
53  end subroutine
54  pure integer function modulefunc2(n)
55    integer, value :: n
56    modulefunc2 = n
57  end function
58end module
59