Break circular dependency between FIR dialect and utilities
[llvm-project.git] / flang / test / Semantics / resolve69.f90
blobe5bdac5205e2eba26debc2147b408915f55478b5
1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 subroutine s1()
3 ! C701 (R701) The type-param-value for a kind type parameter shall be a
4 ! constant expression.
6 ! C702 (R701) A colon shall not be used as a type-param-value except in the
7 ! declaration of an entity that has the POINTER or ALLOCATABLE attribute.
9 ! C704 (R703) In a declaration-type-spec, every type-param-value that is
10 ! not a colon or an asterisk shall be a specification expression.
11 ! Section 10.1.11 defines specification expressions
13 ! 15.4.2.2(4)(c) A procedure must have an explicit interface if it has a
14 ! result that has a nonassumed type parameter value that is not a constant
15 ! expression.
17 integer, parameter :: constVal = 1
18 integer :: nonConstVal = 1
19 !ERROR: Invalid specification expression: reference to local entity 'nonconstval'
20 character(nonConstVal) :: colonString1
21 character(len=20, kind=constVal + 1) :: constKindString
22 character(len=:, kind=constVal + 1), pointer :: constKindString1
23 !ERROR: 'constkindstring2' has a type CHARACTER(KIND=2,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
24 character(len=:, kind=constVal + 1) :: constKindString2
25 !ERROR: Must be a constant value
26 character(len=20, kind=nonConstVal) :: nonConstKindString
27 !ERROR: 'deferredstring' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
28 character(len=:) :: deferredString
29 !ERROR: 'colonstring2' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
30 character(:) :: colonString2
31 !OK because of the allocatable attribute
32 character(:), allocatable :: colonString3
33 !ERROR: 'foo1' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
34 character(:), external :: foo1
35 !ERROR: 'foo2' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
36 procedure(character(:)) :: foo2
37 interface
38 function foo3()
39 !ERROR: 'foo3' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
40 character(:) foo3
41 end function
42 end interface
44 !ERROR: Must have INTEGER type, but is REAL(4)
45 character(3.5) :: badParamValue
47 type derived(typeKind, typeLen)
48 integer, kind :: typeKind
49 integer, len :: typeLen
50 character(typeKind) :: kindValue
51 character(typeLen) :: lenValue
52 end type derived
54 type (derived(constVal, 3)) :: constDerivedKind
55 !ERROR: Value of kind type parameter 'typekind' (nonconstval) must be a scalar INTEGER constant
56 !ERROR: Invalid specification expression: reference to local entity 'nonconstval'
57 type (derived(nonConstVal, 3)) :: nonConstDerivedKind
59 !OK because all type-params are constants
60 type (derived(3, constVal)) :: constDerivedLen
62 !ERROR: Invalid specification expression: reference to local entity 'nonconstval'
63 type (derived(3, nonConstVal)) :: nonConstDerivedLen
64 !ERROR: 'colonderivedlen' has a type derived(typekind=3_4,typelen=:) with a deferred type parameter but is neither an allocatable nor an object pointer
65 type (derived(3, :)) :: colonDerivedLen
66 !ERROR: 'colonderivedlen1' has a type derived(typekind=:,typelen=:) with a deferred type parameter but is neither an allocatable nor an object pointer
67 type (derived( :, :)) :: colonDerivedLen1
68 type (derived( :, :)), pointer :: colonDerivedLen2
69 type (derived(4, :)), pointer :: colonDerivedLen3
70 end subroutine s1
72 !C702
73 !ERROR: 'f1' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
74 character(:) function f1
75 end function
77 function f2
78 !ERROR: 'f2' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
79 character(:) f2
80 end function
82 function f3() result(res)
83 !ERROR: 'res' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
84 character(:) res
85 end function
87 !ERROR: 'f4' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
88 function f4
89 implicit character(:)(f)
90 end function
92 !Not errors.
94 Program d5
95 Type string(maxlen)
96 Integer,Kind :: maxlen
97 Character(maxlen) :: value
98 End Type
99 Type(string(80)) line
100 line%value = 'ok'
101 Print *,Trim(line%value)
102 End Program
104 subroutine outer
105 integer n
106 contains
107 character(n) function inner1()
108 inner1 = ''
109 end function inner1
110 function inner2()
111 real inner2(n)
112 end function inner2
113 end subroutine outer
115 subroutine s2(dp,dpp)
116 !ERROR: 'dp' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
117 procedure(character(:)) :: dp
118 !ERROR: 'dpp' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
119 procedure(character(:)), pointer :: dpp
120 !ERROR: 'pp' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
121 procedure(character(:)), pointer :: pp
122 !ERROR: 'xp' has a type CHARACTER(KIND=1,LEN=:) with a deferred type parameter but is neither an allocatable nor an object pointer
123 procedure(character(:)) :: xp
124 end subroutine