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: Type specification 'pdt(kind=*,len=*)' must be an extension of TYPE 'pdt(kind=1_4,len=:)'
204 type is (pdt(kind
=*, len
=*))
209 subroutine CheckC1163
212 shape_lim_polymorphic
=> rect_obj
213 unlim_polymorphic
=> shape_obj
214 select
type (shape_lim_polymorphic
)
216 !ERROR: Type specification 'shape' conflicts with previous type specification
219 !ERROR: Type specification 'square' conflicts with previous type specification
222 select
type (unlim_polymorphic
)
225 !ERROR: Type specification 'INTEGER(4)' conflicts with previous type specification
230 subroutine CheckC1164
232 shape_lim_polymorphic
=> rect_obj
233 unlim_polymorphic
=> shape_obj
234 select
type (shape_lim_polymorphic
)
236 !ERROR: Type specification 'DEFAULT' conflicts with previous type specification
240 !ERROR: Type specification 'DEFAULT' conflicts with previous type specification
244 !Saving computation if some error in guard by not computing RepeatingCases
245 select
type (shape_lim_polymorphic
)
248 !ERROR: The type specification statement must not specify a type with a SEQUENCE attribute or a BIND attribute
249 TYPE IS(withSequence
)
253 subroutine WorkingPolymorphism
256 shape_lim_polymorphic
=> rect_obj
257 unlim_polymorphic
=> shape_obj
258 select
type (shape_lim_polymorphic
)
260 print *, "hello shape"
262 print *, "hello rect"
264 print *, "hello square"
268 print *, "unlim polymorphism"
269 select
type (unlim_polymorphic
)
271 print *, "hello shape"
273 print *, "hello rect"
275 print *, "hello square"