1 ! RUN: %S/test_errors.sh %s %t %flang_fc1
3 ! Test for checking select type constraints,
13 type, extends(shape
) :: rectangle
18 type, extends(rectangle
) :: square
21 type, extends(square
) :: extsquare
25 logical :: some_logical
33 type, BIND(C
) :: withBind
34 INTEGER(c_int
) ::int_in_c
37 TYPE(shape
), TARGET
:: shape_obj
38 TYPE(rectangle
), TARGET
:: rect_obj
39 TYPE(square
), TARGET
:: squr_obj
40 !define polymorphic objects
41 class(*), pointer :: unlim_polymorphic
42 class(shape
), pointer :: shape_lim_polymorphic
49 subroutine CheckC1160( a
)
50 class(*), intent(in
) :: a
52 !ERROR: The type specification statement must have LEN type parameter as assumed
53 type is ( character(len
=10) ) !<-- assumed length-type
55 type is ( character(len
=*) )
56 !ERROR: The type specification statement must have LEN type parameter as assumed
59 type is ( t(n
=*) ) !<-- assumed length-type
60 !ERROR: Derived type 'character' not found
61 class
is ( character(len
=10) ) !<-- assumed length-type
68 class(*), allocatable
:: x
70 TYPE(derived(10)) :: a
71 select
type (ax
=> a
%x
)
72 class
is (derived(param
=*))
80 integer, parameter :: const_var
=10
81 !ERROR: Selector is not a named variable: 'associate-name =>' is required
84 !ERROR: Selector is not a named variable: 'associate-name =>' is required
85 select
type(const_var
)
87 !ERROR: Selector is not a named variable: 'associate-name =>' is required
90 !ERROR: Selector is not a named variable: 'associate-name =>' is required
91 select
type (shape_obj
%x
)
95 !CheckPloymorphicSelectorType
96 subroutine CheckC1159a
97 integer :: int_variable
99 complex :: complex_var
= cmplx(3.0, 4.0)
100 logical :: log_variable
101 character (len
=10) :: char_variable
= "OM"
102 !ERROR: Selector 'int_variable' in SELECT TYPE statement must be polymorphic
103 select
type (int_variable
)
105 !ERROR: Selector 'real_variable' in SELECT TYPE statement must be polymorphic
106 select
type (real_variable
)
108 !ERROR: Selector 'complex_var' in SELECT TYPE statement must be polymorphic
109 select
type(complex_var
)
111 !ERROR: Selector 'logical_variable' in SELECT TYPE statement must be polymorphic
112 select
type(logical_variable
)
114 !ERROR: Selector 'char_variable' in SELECT TYPE statement must be polymorphic
115 select
type(char_variable
)
119 subroutine CheckC1159b
121 !ERROR: Selector 'x' in SELECT TYPE statement must be polymorphic
123 !ERROR: If selector is not unlimited polymorphic, an intrinsic type specification must not be specified in the type guard statement
129 subroutine CheckC1159c
130 !ERROR: Selector 'x' in SELECT TYPE statement must be polymorphic
132 !ERROR: If selector is not unlimited polymorphic, an intrinsic type specification must not be specified in the type guard statement
145 subroutine CheckC1161
147 shape_lim_polymorphic
=> rect_obj
148 select
type(shape_lim_polymorphic
)
149 !ERROR: The type specification statement must not specify a type with a SEQUENCE attribute or a BIND attribute
150 type is (withSequence
)
151 !ERROR: The type specification statement must not specify a type with a SEQUENCE attribute or a BIND attribute
156 subroutine CheckC1162
158 class(rectangle
), pointer :: rectangle_polymorphic
159 !not unlimited polymorphic objects
160 select
type (rectangle_polymorphic
)
161 !ERROR: Type specification 'shape' must be an extension of TYPE 'rectangle'
163 !ERROR: Type specification 'unrelated' must be an extension of TYPE 'rectangle'
170 !ERROR: If selector is not unlimited polymorphic, an intrinsic type specification must not be specified in the type guard statement
172 !ERROR: If selector is not unlimited polymorphic, an intrinsic type specification must not be specified in the type guard statement
174 !ERROR: If selector is not unlimited polymorphic, an intrinsic type specification must not be specified in the type guard statement
176 !ERROR: If selector is not unlimited polymorphic, an intrinsic type specification must not be specified in the type guard statement
177 type is(character(len
=*))
178 !ERROR: If selector is not unlimited polymorphic, an intrinsic type specification must not be specified in the type guard statement
182 !Unlimited polymorphic objects are allowed.
183 unlim_polymorphic
=> rect_obj
184 select
type (unlim_polymorphic
)
190 subroutine CheckC1163
193 shape_lim_polymorphic
=> rect_obj
194 unlim_polymorphic
=> shape_obj
195 select
type (shape_lim_polymorphic
)
197 !ERROR: Type specification 'shape' conflicts with previous type specification
200 !ERROR: Type specification 'square' conflicts with previous type specification
203 select
type (unlim_polymorphic
)
206 !ERROR: Type specification 'INTEGER(4)' conflicts with previous type specification
211 subroutine CheckC1164
213 shape_lim_polymorphic
=> rect_obj
214 unlim_polymorphic
=> shape_obj
215 select
type (shape_lim_polymorphic
)
217 !ERROR: Type specification 'DEFAULT' conflicts with previous type specification
221 !ERROR: Type specification 'DEFAULT' conflicts with previous type specification
225 !Saving computation if some error in guard by not computing RepeatingCases
226 select
type (shape_lim_polymorphic
)
229 !ERROR: The type specification statement must not specify a type with a SEQUENCE attribute or a BIND attribute
230 TYPE IS(withSequence
)
234 subroutine WorkingPolymorphism
237 shape_lim_polymorphic
=> rect_obj
238 unlim_polymorphic
=> shape_obj
239 select
type (shape_lim_polymorphic
)
241 print *, "hello shape"
243 print *, "hello rect"
245 print *, "hello square"
249 print *, "unlim polymorphism"
250 select
type (unlim_polymorphic
)
252 print *, "hello shape"
254 print *, "hello rect"
256 print *, "hello square"