48 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12! Error tests for structure constructors: per-component type3! (in)compatibility.4 5module module16 interface7 real function realfunc(x)8 real, value :: x9 end function realfunc10 end interface11 type :: scalar(ik,rk,zk,ck,lk,len)12 integer, kind :: ik = 4, rk = 4, zk = 4, ck = 1, lk = 113 integer, len :: len = 114 integer(kind=ik) :: ix = int(0,kind=ik)15 real(kind=rk) :: rx = real(0.,kind=rk)16 complex(kind=zk) :: zx = cmplx(0.,0.,kind=zk)17 !ERROR: Initialization expression for 'cx' (" ") cannot be computed as a constant value18 character(kind=ck,len=len) :: cx = ' '19 logical(kind=lk) :: lx = .false.20 real(kind=rk), pointer :: rp => NULL()21 procedure(realfunc), pointer, nopass :: rfp1 => NULL()22 procedure(real), pointer, nopass :: rfp2 => NULL()23 end type scalar24 contains25 subroutine scalararg(x)26 type(scalar), intent(in) :: x27 end subroutine scalararg28 subroutine errors(n)29 integer, intent(in) :: n30 call scalararg(scalar(4)()) ! ok31 !ERROR: Structure constructor lacks a value for component 'cx'32 call scalararg(scalar(len=n)()) ! triggers error on 'cx'33 call scalararg(scalar(4)(ix=1,rx=2.,zx=(3.,4.),cx='a',lx=.true.))34 call scalararg(scalar(4)(1,2.,(3.,4.),'a',.true.))35! call scalararg(scalar(4)(ix=5.,rx=6,zx=(7._8,8._2),cx=4_'b',lx=.true._4))36! call scalararg(scalar(4)(5.,6,(7._8,8._2),4_'b',.true._4))37 call scalararg(scalar(4)(ix=5.,rx=6,zx=(7._8,8._2),cx=4_'b',lx=.true.))38 call scalararg(scalar(4)(5.,6,(7._8,8._2),4_'b',.true.))39 !ERROR: Value in structure constructor of type 'CHARACTER(KIND=1,LEN=1_8)' is incompatible with component 'ix' of type 'INTEGER(4)'40 call scalararg(scalar(4)(ix='a'))41 !ERROR: Value in structure constructor of type 'LOGICAL(4)' is incompatible with component 'ix' of type 'INTEGER(4)'42 call scalararg(scalar(4)(ix=.false.))43 !ERROR: Rank-1 array value is not compatible with scalar component 'ix'44 call scalararg(scalar(4)(ix=[1]))45 !TODO more!46 end subroutine errors47end module module148