1 ! RUN: %python %S/test_errors.py %s %flang_fc1
2 ! Test for checking select type constraints,
12 type, extends(shape
) :: rectangle
17 type, extends(rectangle
) :: square
20 type, extends(square
) :: extsquare
24 logical :: some_logical
32 type, BIND(C
) :: withBind
33 INTEGER(c_int
) ::int_in_c
36 TYPE(shape
), TARGET
:: shape_obj
37 TYPE(rectangle
), TARGET
:: rect_obj
38 TYPE(square
), TARGET
:: squr_obj
39 !define polymorphic objects
40 class(*), pointer :: unlim_polymorphic
41 class(shape
), pointer :: shape_lim_polymorphic
48 subroutine CheckC1160( a
)
49 class(*), intent(in
) :: a
51 !ERROR: The type specification statement must have LEN type parameter as assumed
52 type is ( character(len
=10) ) !<-- assumed length-type
53 !ERROR: The type specification statement must have LEN type parameter as assumed
56 type is ( character(len
=*) )
57 !ERROR: The type specification statement must have LEN type parameter as assumed
60 type is ( t(n
=*) ) !<-- assumed length-type
61 !ERROR: Derived type 'character' not found
62 class
is ( character(len
=10) ) !<-- assumed length-type
69 class(*), allocatable
:: x
71 TYPE(derived(10)) :: a
72 select
type (ax
=> a
%x
)
73 class
is (derived(param
=*))
81 integer, parameter :: const_var
=10
82 !ERROR: Selector is not a named variable: 'associate-name =>' is required
85 !ERROR: Selector is not a named variable: 'associate-name =>' is required
86 select
type(const_var
)
88 !ERROR: Selector is not a named variable: 'associate-name =>' is required
91 !ERROR: Selector is not a named variable: 'associate-name =>' is required
92 select
type (shape_obj
%x
)
96 !CheckPloymorphicSelectorType
97 subroutine CheckC1159a
98 integer :: int_variable
100 complex :: complex_var
= cmplx(3.0, 4.0)
101 logical :: log_variable
102 character (len
=10) :: char_variable
= "OM"
103 !ERROR: Selector 'int_variable' in SELECT TYPE statement must be polymorphic
104 select
type (int_variable
)
106 !ERROR: Selector 'real_variable' in SELECT TYPE statement must be polymorphic
107 select
type (real_variable
)
109 !ERROR: Selector 'complex_var' in SELECT TYPE statement must be polymorphic
110 select
type(complex_var
)
112 !ERROR: Selector 'logical_variable' in SELECT TYPE statement must be polymorphic
113 select
type(logical_variable
)
115 !ERROR: Selector 'char_variable' in SELECT TYPE statement must be polymorphic
116 select
type(char_variable
)
120 subroutine CheckC1159b
122 !ERROR: Selector 'x' in SELECT TYPE statement must be polymorphic
124 !ERROR: If selector is not unlimited polymorphic, an intrinsic type specification must not be specified in the type guard statement
130 subroutine CheckC1159c
131 !ERROR: Selector 'x' in SELECT TYPE statement must be polymorphic
133 !ERROR: If selector is not unlimited polymorphic, an intrinsic type specification must not be specified in the type guard statement
146 subroutine CheckC1161
148 shape_lim_polymorphic
=> rect_obj
149 select
type(shape_lim_polymorphic
)
150 !ERROR: The type specification statement must not specify a type with a SEQUENCE attribute or a BIND attribute
151 type is (withSequence
)
152 !ERROR: The type specification statement must not specify a type with a SEQUENCE attribute or a BIND attribute
157 subroutine CheckC1162
159 class(rectangle
), pointer :: rectangle_polymorphic
160 !not unlimited polymorphic objects
161 select
type (rectangle_polymorphic
)
162 !ERROR: Type specification 'shape' must be an extension of TYPE 'rectangle'
164 !ERROR: Type specification 'unrelated' must be an extension of TYPE 'rectangle'
171 !ERROR: If selector is not unlimited polymorphic, an intrinsic type specification must not be specified in the type guard statement
173 !ERROR: If selector is not unlimited polymorphic, an intrinsic type specification must not be specified in the type guard statement
175 !ERROR: If selector is not unlimited polymorphic, an intrinsic type specification must not be specified in the type guard statement
177 !ERROR: If selector is not unlimited polymorphic, an intrinsic type specification must not be specified in the type guard statement
178 type is(character(len
=*))
179 !ERROR: If selector is not unlimited polymorphic, an intrinsic type specification must not be specified in the type guard statement
183 !Unlimited polymorphic objects are allowed.
184 unlim_polymorphic
=> rect_obj
185 select
type (unlim_polymorphic
)
193 integer, kind
:: kind
198 class(pdt(kind
=1,len
=:)), allocatable
:: x
200 type is (pdt(kind
=1, len
=*))
201 !ERROR: Type specification 'pdt(kind=2_4,len=*)' must be an extension of TYPE 'pdt(kind=1_4,len=:)'
202 type is (pdt(kind
=2, len
=*))
203 !ERROR: Value of KIND type parameter 'kind' must be constant
204 !ERROR: Type specification 'pdt(kind=*,len=*)' must be an extension of TYPE 'pdt(kind=1_4,len=:)'
205 type is (pdt(kind
=*, len
=*))
210 subroutine CheckC1163
213 shape_lim_polymorphic
=> rect_obj
214 unlim_polymorphic
=> shape_obj
215 select
type (shape_lim_polymorphic
)
217 !ERROR: Type specification 'shape' conflicts with previous type specification
220 !ERROR: Type specification 'square' conflicts with previous type specification
223 select
type (unlim_polymorphic
)
226 !ERROR: Type specification 'INTEGER(4)' conflicts with previous type specification
231 subroutine CheckC1164
233 shape_lim_polymorphic
=> rect_obj
234 unlim_polymorphic
=> shape_obj
235 select
type (shape_lim_polymorphic
)
237 !ERROR: Type specification 'DEFAULT' conflicts with previous type specification
241 !ERROR: Type specification 'DEFAULT' conflicts with previous type specification
245 !Saving computation if some error in guard by not computing RepeatingCases
246 select
type (shape_lim_polymorphic
)
249 !ERROR: The type specification statement must not specify a type with a SEQUENCE attribute or a BIND attribute
250 TYPE IS(withSequence
)
254 subroutine WorkingPolymorphism
257 shape_lim_polymorphic
=> rect_obj
258 unlim_polymorphic
=> shape_obj
259 select
type (shape_lim_polymorphic
)
261 print *, "hello shape"
263 print *, "hello rect"
265 print *, "hello square"
269 print *, "unlim polymorphism"
270 select
type (unlim_polymorphic
)
272 print *, "hello shape"
274 print *, "hello rect"
276 print *, "hello square"
282 subroutine CheckNotProcedure
284 !ERROR: Selector may not be a procedure
288 function f() result(res
)
289 class(shape
), allocatable
:: res
292 subroutine CheckAssumedRankInSelectType(var
)
293 class(*), intent(in
) :: var(..)
294 !ERROR: Assumed-rank variable may only be used as actual argument