brintos

brintos / llvm-project-archived public Read only

0
0
Text · 10.2 KiB · 0c3df2e Raw
379 lines · plain
1! RUN: %python %S/test_errors.py %s %flang_fc12! Invalid operand types when user-defined operator is available3module m14  type :: t5  end type6  interface operator(==)7    logical function eq_tt(x, y)8      import :: t9      type(t), intent(in) :: x, y10    end11  end interface12  interface operator(+)13    logical function add_tr(x, y)14      import :: t15      type(t), intent(in) :: x16      real, intent(in) :: y17    end18    logical function plus_t(x)19      import :: t20      type(t), intent(in) :: x21    end22    logical function add_12(x, y)23      real, intent(in) :: x(:), y(:,:)24    end25  end interface26  interface operator(.and.)27    logical function and_tr(x, y)28      import :: t29      type(t), intent(in) :: x30      real, intent(in) :: y31    end32  end interface33  interface operator(//)34    logical function concat_tt(x, y)35      import :: t36      type(t), intent(in) :: x, y37    end38  end interface39  interface operator(.not.)40    logical function not_r(x)41      real, intent(in) :: x42    end43  end interface44  type(t) :: x, y45  real :: r46  logical :: l47  integer :: iVar48  complex :: cvar49  character :: charVar50contains51  subroutine test_relational()52    l = x == y  !OK53    l = x .eq. y  !OK54    l = x .eq. y  !OK55    l = iVar == z'fe' !OK56    l = z'fe' == iVar !OK57    l = r == z'fe' !OK58    l = z'fe' == r !OK59    l = cVar == z'fe' !OK60    l = z'fe' == cVar !OK61    !ERROR: Operands of .EQ. must have comparable types; have CHARACTER(KIND=1) and INTEGER(4)62    l = charVar == z'fe'63    !ERROR: Operands of .EQ. must have comparable types; have INTEGER(4) and CHARACTER(KIND=1)64    l = z'fe' == charVar65    !ERROR: Operands of .EQ. must have comparable types; have LOGICAL(4) and INTEGER(4)66    l = l == z'fe'67    !ERROR: Operands of .EQ. must have comparable types; have INTEGER(4) and LOGICAL(4)68    l = z'fe' == l69    !ERROR: Operands of .EQ. must have comparable types; have TYPE(t) and REAL(4)70    l = x == r71 72    lVar = z'a' == b'1010' !OK73  end74  subroutine test_numeric()75    l = x + r  !OK76    !ERROR: No intrinsic or user-defined OPERATOR(+) matches operand types REAL(4) and TYPE(t)77    l = r + x78  end79  subroutine test_logical()80    l = x .and. r  !OK81    !ERROR: No intrinsic or user-defined OPERATOR(.AND.) matches operand types REAL(4) and TYPE(t)82    l = r .and. x83  end84  subroutine test_unary()85    l = +x  !OK86    !ERROR: No intrinsic or user-defined OPERATOR(+) matches operand type LOGICAL(4)87    l = +l88    l = .not. r  !OK89    !ERROR: No intrinsic or user-defined OPERATOR(.NOT.) matches operand type TYPE(t)90    l = .not. x91  end92  subroutine test_concat()93    l = x // y  !OK94    !ERROR: No intrinsic or user-defined OPERATOR(//) matches operand types TYPE(t) and REAL(4)95    l = x // r96  end97  subroutine test_conformability(x, y)98    real :: x(10), y(10,10)99    l = x + y  !OK100    !ERROR: No intrinsic or user-defined OPERATOR(+) matches rank 2 array of REAL(4) and rank 1 array of REAL(4)101    l = y + x102  end103end104 105! Invalid operand types when user-defined operator is not available106module m2107  intrinsic :: sin108  type :: t109  end type110  type(t) :: x, y111  real :: r112  logical :: l113contains114  subroutine test_relational()115    !ERROR: Operands of .EQ. must have comparable types; have TYPE(t) and REAL(4)116    l = x == r117    !ERROR: Subroutine name is not allowed here118    l = r == test_numeric119    !ERROR: Function call must have argument list120    l = r == sin121  end122  subroutine test_numeric()123    !ERROR: Operands of + must be numeric; have REAL(4) and TYPE(t)124    l = r + x125  end126  subroutine test_logical()127    !ERROR: Operands of .AND. must be LOGICAL; have REAL(4) and TYPE(t)128    l = r .and. x129  end130  subroutine test_unary()131    !ERROR: Operand of unary + must be numeric; have LOGICAL(4)132    l = +l133    !ERROR: Operand of .NOT. must be LOGICAL; have TYPE(t)134    l = .not. x135  end136  subroutine test_concat(a, b)137    character(4,kind=1) :: a138    character(4,kind=2) :: b139    character(4) :: c140    !ERROR: Operands of // must be CHARACTER with the same kind; have CHARACTER(KIND=1) and CHARACTER(KIND=2)141    c = a // b142    !ERROR: Operands of // must be CHARACTER with the same kind; have TYPE(t) and REAL(4)143    l = x // r144  end145  subroutine test_conformability(x, y)146    real :: x(10), y(10,10)147    !ERROR: Operands of + are not conformable; have rank 2 and rank 1148    l = y + x149  end150end151 152! Invalid untyped operands: user-defined operator doesn't affect errors153module m3154  interface operator(+)155    logical function add(x, y)156      logical, intent(in) :: x157      integer, value :: y158    end159  end interface160contains161  subroutine s1(x, y)162    logical :: x163    integer :: y164    integer, pointer :: px165    logical :: l166    complex :: z167    y = y + z'1'  !OK168    !ERROR: No intrinsic or user-defined OPERATOR(+) matches operand types untyped and COMPLEX(4)169    z = z'1' + z170    y = +z'1'  !OK171    !ERROR: Operand of unary - must be numeric; have untyped172    y = -z'1'173    y = x + z'1' ! matches "add" with conversion of untyped to integer174    !ERROR: A NULL() pointer is not allowed as an operand here175    l = x /= null()176    !ERROR: A NULL() pointer is not allowed as a relational operand177    l = null(px) /= null(px)178    !ERROR: A NULL() pointer is not allowed as an operand here179    l = x /= null(px)180    !ERROR: A NULL() pointer is not allowed as an operand here181    l = px /= null()182    !ERROR: A NULL() pointer is not allowed as a relational operand183    l = px /= null(px)184    !ERROR: A NULL() pointer is not allowed as an operand here185    l = null() /= null()186  end187end188 189! Test alternate operators. They aren't enabled by default so should be190! treated as defined operators, not intrinsic ones.191module m4192contains193  subroutine s1(x, y, z)194    logical :: x195    real :: y, z196    !ERROR: No operator .A. defined for REAL(4) and REAL(4)197    x = y .a. z198    !ERROR: No operator .O. defined for REAL(4) and REAL(4)199    x = y .o. z200    !ERROR: No operator .N. defined for REAL(4)201    x = .n. y202    !ERROR: No operator .XOR. defined for REAL(4) and REAL(4)203    x = y .xor. z204    !ERROR: No operator .X. defined for REAL(4)205    x = .x. y206  end207end208 209! Like m4 in resolve63 but compiled with different options.210! .A. is a defined operator.211module m5212  interface operator(.A.)213    logical function f1(x, y)214      integer, intent(in) :: x, y215    end216  end interface217  interface operator(.and.)218    logical function f2(x, y)219      real, intent(in) :: x, y220    end221  end interface222contains223  subroutine s1(x, y, z)224    logical :: x225    complex :: y, z226    !ERROR: No intrinsic or user-defined OPERATOR(.AND.) matches operand types COMPLEX(4) and COMPLEX(4)227    x = y .and. z228    !ERROR: No intrinsic or user-defined .A. matches operand types COMPLEX(4) and COMPLEX(4)229    x = y .a. z230  end231end232 233! Type-bound operators234module m6235  type :: t1236  contains237    procedure, pass(x) :: p1 => f1238    generic :: operator(+) => p1239  end type240  type, extends(t1) :: t2241  contains242    procedure, pass(y) :: p2 => f2243    generic :: operator(+) => p2244  end type245  type :: t3246  contains247    procedure, nopass :: p1 => f1248    !ERROR: OPERATOR(+) procedure 'p1' may not have NOPASS attribute249    generic :: operator(+) => p1250  end type251contains252  integer function f1(x, y)253    class(t1), intent(in) :: x254    integer, intent(in) :: y255  end256  integer function f2(x, y)257    class(t1), intent(in) :: x258    class(t2), intent(in) :: y259  end260  subroutine test(x, y, z)261    class(t1) :: x262    class(t2) :: y263    integer :: i264    i = x + y265    i = x + i266    i = y + i267    !ERROR: Operands of + must be numeric; have CLASS(t2) and CLASS(t1)268    i = y + x269    !ERROR: Operands of + must be numeric; have INTEGER(4) and CLASS(t1)270    i = i + x271  end272end273 274! Some cases where NULL is acceptable - ensure no false errors275module m7276  implicit none277  type :: t1278   contains279    procedure :: s1280    generic :: operator(/) => s1281  end type282  interface operator(-)283    module procedure s2284  end interface285 contains286  integer function s1(x, y)287    class(t1), intent(in) :: x288    class(t1), intent(in), pointer :: y289    s1 = 1290  end291  integer function s2(x, y)292    type(t1), intent(in), pointer :: x, y293    s2 = 2294  end295  subroutine test296    integer :: j297    type(t1), pointer :: x1298    allocate(x1)299    ! These cases are fine.300    j = x1 - x1301    j = x1 - null(mold=x1)302    j = null(mold=x1) - null(mold=x1)303    j = null(mold=x1) - x1304    j = x1 / x1305    j = x1 / null(mold=x1)306    j = null() - null(mold=x1)307    j = null(mold=x1) - null()308    j = null() - null()309    !ERROR: A NULL() pointer is not allowed as an operand here310    j = null() / null(mold=x1)311    !ERROR: A NULL() pointer is not allowed as an operand here312    j = null(mold=x1) / null()313    !ERROR: A NULL() pointer is not allowed as an operand here314    j = null() / null()315  end316end317 318! 16.9.144(6)319module m8320  interface generic321    procedure s1, s2322  end interface323 contains324  subroutine s1(ip1, rp1)325    integer, pointer, intent(in) :: ip1326    real, pointer, intent(in) :: rp1327  end subroutine328  subroutine s2(rp2, ip2)329    real, pointer, intent(in) :: rp2330    integer, pointer, intent(in) :: ip2331  end subroutine332  subroutine test333    integer, pointer :: ip334    real, pointer :: rp335    call generic(ip, rp) ! ok336    call generic(ip, null()) ! ok337    call generic(rp, null()) ! ok338    call generic(null(), rp) ! ok339    call generic(null(), ip) ! ok340    call generic(null(mold=ip), null()) ! ok341    call generic(null(), null(mold=ip)) ! ok342    !ERROR: The actual arguments to the generic procedure 'generic' matched multiple specific procedures, perhaps due to use of NULL() without MOLD= or an actual procedure with an implicit interface343    call generic(null(), null())344  end subroutine345end346 347module m9348  interface generic349    procedure s1, s2350  end interface351 contains352  subroutine s1(jf)353    procedure(integer) :: jf354  end subroutine355  subroutine s2(af)356    procedure(real) :: af357  end subroutine358  subroutine test359    external underspecified360    !ERROR: The actual arguments to the generic procedure 'generic' matched multiple specific procedures, perhaps due to use of NULL() without MOLD= or an actual procedure with an implicit interface361    call generic(underspecified)362  end subroutine363end module364 365! Ensure no bogus errors for assignments to CLASS(*) allocatable366module m10367  type :: t1368    integer :: n369  end type370 contains371  subroutine test372    class(*), allocatable :: poly373    poly = 1374    poly = 3.14159375    poly = 'Il faut imaginer Sisyphe heureux'376    poly = t1(1)377  end subroutine378end module379