142 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12! Test various conditions in C1158.3implicit none4 5type :: t16 integer :: i7end type8 9type, extends(t1) :: t210end type11 12type(t1),target :: x113type(t2),target :: x214 15class(*), pointer :: ptr16class(t1), pointer :: p_or_c17!vector subscript related18class(t1),DIMENSION(:,:),allocatable::array119class(t2),DIMENSION(:,:),allocatable::array220integer, dimension(2) :: V21V = (/ 1,2 /)22allocate(array1(3,3))23allocate(array2(3,3))24 25! A) associate with function, i.e (other than variables)26select type ( y => fun(1) )27 type is (t1)28 print *, rank(y%i)29end select30 31select type ( y => fun(1) )32 type is (t1)33 y%i = 1 !VDC34 type is (t2)35 call sub_with_in_and_inout_param(y,y) !VDC36end select37 38select type ( y => (fun(1)) )39 type is (t1)40 !ERROR: Left-hand side of assignment is not definable41 !BECAUSE: 'y' is construct associated with an expression42 y%i = 1 !VDC43 type is (t2)44 !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'z=' is not definable45 !BECAUSE: 'y' is construct associated with an expression46 call sub_with_in_and_inout_param(y,y) !VDC47end select48 49! B) associated with a variable:50p_or_c => x151select type ( a => p_or_c )52 type is (t1)53 a%i = 1054end select55 56select type ( a => p_or_c )57 type is (t1)58end select59 60!C)Associate with with vector subscript61select type (b => array1(V,2))62 type is (t1)63 !ERROR: Left-hand side of assignment is not definable64 !BECAUSE: Construct association 'b' has a vector subscript65 b%i = 1 !VDC66 type is (t2)67 !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'z=' is not definable68 !BECAUSE: Construct association 'b' has a vector subscript69 call sub_with_in_and_inout_param_vector(b,b) !VDC70end select71select type(b => foo(1) )72 type is (t1)73 !ERROR: Left-hand side of assignment is not definable74 !BECAUSE: 'b' is construct associated with an expression75 b%i = 1 !VDC76 type is (t2)77 !ERROR: Actual argument associated with INTENT(IN OUT) dummy argument 'z=' is not definable78 !BECAUSE: 'b' is construct associated with an expression79 call sub_with_in_and_inout_param_vector(b,b) !VDC80end select81 82!D) Have no association and should be ok.83!1. points to function84ptr => fun(1)85select type ( ptr )86type is (t1)87 ptr%i = 188end select89 90!2. points to variable91ptr=>x192select type (ptr)93 type is (t1)94 ptr%i = 1095end select96 97contains98 99 function fun(i)100 class(t1),pointer :: fun101 integer :: i102 if (i>0) then103 fun => x1104 else if (i<0) then105 fun => x2106 else107 fun => NULL()108 end if109 end function110 111 function foo(i)112 integer :: i113 class(t1),DIMENSION(:),allocatable :: foo114 integer, dimension(2) :: U115 U = (/ 1,2 /)116 if (i>0) then117 foo = array1(2,U)118 else if (i<0) then119 foo = array2(2,U) ! ok: t2 extends t1120 end if121 end function122 123 function foo2()124 class(t2),DIMENSION(:),allocatable :: foo2125 !ERROR: No intrinsic or user-defined ASSIGNMENT(=) matches operand types CLASS(t2) and CLASS(t1)126 foo2 = array1(2,:)127 end function128 129 subroutine sub_with_in_and_inout_param(y, z)130 type(t2), INTENT(IN) :: y131 class(t2), INTENT(INOUT) :: z132 z%i = 10133 end subroutine134 135 subroutine sub_with_in_and_inout_param_vector(y, z)136 type(t2),DIMENSION(:), INTENT(IN) :: y137 class(t2),DIMENSION(:), INTENT(INOUT) :: z138 z%i = 10139 end subroutine140 141end142