xref: /llvm-project/flang/test/Semantics/expr-errors04.f90 (revision f13d6001324e9c9653d8568c1d86e182b217e272)
148a70ea1SPeixin-Qiao! RUN: %python %S/test_errors.py %s %flang_fc1
248a70ea1SPeixin-Qiao! Regression test for more than one part-ref with nonzero rank
348a70ea1SPeixin-Qiao
448a70ea1SPeixin-Qiaoprogram m
5c6d8aa27SPeixin-Qiao  interface
6c6d8aa27SPeixin-Qiao    function real_info1(i)
7c6d8aa27SPeixin-Qiao    end
8c6d8aa27SPeixin-Qiao    subroutine real_info2()
9c6d8aa27SPeixin-Qiao    end
10c6d8aa27SPeixin-Qiao    subroutine real_generic()
11c6d8aa27SPeixin-Qiao    end
12c6d8aa27SPeixin-Qiao  end interface
1348a70ea1SPeixin-Qiao  type mt
1448a70ea1SPeixin-Qiao    complex :: c, c2(2)
1548a70ea1SPeixin-Qiao    integer :: x, x2(2)
1648a70ea1SPeixin-Qiao    character(10) :: s, s2(2)
17ddb35533SPeter Klausler    real, pointer :: p
18ddb35533SPeter Klausler    real, allocatable :: a
19c6d8aa27SPeixin-Qiao   contains
20c6d8aa27SPeixin-Qiao    procedure, nopass :: info1 => real_info1
21c6d8aa27SPeixin-Qiao    procedure, nopass :: info2 => real_info2
22c6d8aa27SPeixin-Qiao    procedure, nopass :: real_generic
23c6d8aa27SPeixin-Qiao    generic :: g1 => real_generic
2448a70ea1SPeixin-Qiao  end type
2548a70ea1SPeixin-Qiao  type mt2
2648a70ea1SPeixin-Qiao    type(mt) :: t1(2,2)
2748a70ea1SPeixin-Qiao  end type
2848a70ea1SPeixin-Qiao  type mt3
2948a70ea1SPeixin-Qiao    type(mt2) :: t2(2)
3048a70ea1SPeixin-Qiao  end type
3148a70ea1SPeixin-Qiao  type mt4
3248a70ea1SPeixin-Qiao    type(mt3) :: t3(2)
3348a70ea1SPeixin-Qiao  end type
3448a70ea1SPeixin-Qiao  type(mt4) :: t(2)
3548a70ea1SPeixin-Qiao
3648a70ea1SPeixin-Qiao  print *, t(1)%t3(1)%t2(1)%t1%x ! no error
3748a70ea1SPeixin-Qiao  print *, t(1)%t3(1)%t2(1)%t1%x2(1) ! no error
3848a70ea1SPeixin-Qiao  print *, t(1)%t3(1)%t2(1)%t1%s(1:2) ! no error
3948a70ea1SPeixin-Qiao  print *, t(1)%t3(1)%t2(1)%t1%s2(1)(1:2) ! no error
4048a70ea1SPeixin-Qiao  print *, t(1)%t3(1)%t2(1)%t1%c%RE ! no error
4148a70ea1SPeixin-Qiao  print *, t(1)%t3(1)%t2(1)%t1%c%IM ! no error
4248a70ea1SPeixin-Qiao  print *, t(1)%t3(1)%t2(1)%t1%c2(1)%RE ! no error
4348a70ea1SPeixin-Qiao  print *, t(1)%t3(1)%t2(1)%t1%c2(1)%IM ! no error
4448a70ea1SPeixin-Qiao
4548a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
4648a70ea1SPeixin-Qiao  print *, t%t3%t2%t1%x
4748a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
4848a70ea1SPeixin-Qiao  print *, t(1)%t3%t2%t1%x
4948a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
5048a70ea1SPeixin-Qiao  print *, t(1)%t3(1)%t2%t1%x
5148a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
5248a70ea1SPeixin-Qiao  print *, t(1)%t3%t2(1)%t1%x
5348a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
5448a70ea1SPeixin-Qiao  print *, t%t3%t2%t1%x2(1)
5548a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-1 component 'x2' of rank-2 array of derived type is not allowed
5648a70ea1SPeixin-Qiao  print *, t(1)%t3%t2%t1%x2
5748a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
5848a70ea1SPeixin-Qiao  print *, t(1)%t3(1)%t2%t1%x2(1)
5948a70ea1SPeixin-Qiao  !ERROR: Subscripts of component 'x2' of rank-2 derived type array have rank 1 but must all be scalar
6048a70ea1SPeixin-Qiao  print *, t(1)%t3(1)%t2(1)%t1%x2(1:)
6148a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
6248a70ea1SPeixin-Qiao  print *, t%t3%t2%t1%s(1:2)
6348a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
6448a70ea1SPeixin-Qiao  print *, t(1)%t3%t2(1)%t1%s(1:2)
6548a70ea1SPeixin-Qiao  !ERROR: Subscripts of component 't1' of rank-1 derived type array have rank 1 but must all be scalar
6648a70ea1SPeixin-Qiao  print *, t%t3%t2%t1(1,:)%s(1:2)
6748a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
6848a70ea1SPeixin-Qiao  print *, t%t3%t2%t1%s2(1)(1:2)
6948a70ea1SPeixin-Qiao  !ERROR: Subscripts of component 's2' of rank-2 derived type array have rank 1 but must all be scalar
7048a70ea1SPeixin-Qiao  print *, t(1)%t3%t2%t1%s2(1:)(1:2)
7148a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
7248a70ea1SPeixin-Qiao  print *, t%t3%t2%t1%c%RE
7348a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
7448a70ea1SPeixin-Qiao  print *, t(1)%t3%t2%t1%c%RE
7548a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
7648a70ea1SPeixin-Qiao  print *, t(1)%t3(1)%t2%t1%c%RE
7748a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
7848a70ea1SPeixin-Qiao  print *, t(1)%t3%t2(1)%t1%c%RE
7948a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
8048a70ea1SPeixin-Qiao  print *, t%t3%t2%t1%c%IM
8148a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
8248a70ea1SPeixin-Qiao  print *, t%t3%t2%t1%c2(1)%RE
8348a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
8448a70ea1SPeixin-Qiao  print *, t(1)%t3%t2%t1%c2(1)%RE
8548a70ea1SPeixin-Qiao  !ERROR: Subscripts of component 'c2' of rank-2 derived type array have rank 1 but must all be scalar
8648a70ea1SPeixin-Qiao  print *, t(1)%t3(1)%t2%t1%c2(1:)%RE
8748a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
8848a70ea1SPeixin-Qiao  print *, t(1)%t3%t2(1)%t1%c2(1)%RE
8948a70ea1SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
9048a70ea1SPeixin-Qiao  print *, t%t3%t2%t1%c2(1)%IM
91c6d8aa27SPeixin-Qiao
92c6d8aa27SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
93c6d8aa27SPeixin-Qiao  call sub0(t%t3%t2%t1%info1(i))
94c6d8aa27SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
95*f13d6001SKelvin Li  call sub0(t%t3%t2%t1%info1)
96*f13d6001SKelvin Li  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
97c6d8aa27SPeixin-Qiao  call t%t3%t2%t1%info2
98c6d8aa27SPeixin-Qiao  !ERROR: Reference to whole rank-2 component 't1' of rank-1 array of derived type is not allowed
99c6d8aa27SPeixin-Qiao  call t%t3%t2%t1%g1
100c6d8aa27SPeixin-Qiao
101c6d8aa27SPeixin-Qiao  !ERROR: Reference to rank-2 object 't1' has 1 subscripts
102c6d8aa27SPeixin-Qiao  call sub0(t%t3%t2%t1(1)%info1(i))
103c6d8aa27SPeixin-Qiao  !ERROR: Reference to rank-2 object 't1' has 1 subscripts
104*f13d6001SKelvin Li  call sub0(t%t3%t2%t1(1)%info1)
105*f13d6001SKelvin Li  !ERROR: Reference to rank-2 object 't1' has 1 subscripts
106c6d8aa27SPeixin-Qiao  call t%t3%t2%t1(1)%info2
107c6d8aa27SPeixin-Qiao  !ERROR: Reference to rank-2 object 't1' has 1 subscripts
108c6d8aa27SPeixin-Qiao  call t%t3%t2%t1(1)%g1
109c6d8aa27SPeixin-Qiao
110c6d8aa27SPeixin-Qiao  !ERROR: Reference to rank-2 object 't1' has 1 subscripts
111c6d8aa27SPeixin-Qiao  call sub0(t%t3%t2%t1(1:)%info1(i))
112c6d8aa27SPeixin-Qiao  !ERROR: Reference to rank-2 object 't1' has 1 subscripts
113*f13d6001SKelvin Li  call sub0(t%t3%t2%t1(1:)%info1)
114*f13d6001SKelvin Li  !ERROR: Reference to rank-2 object 't1' has 1 subscripts
115c6d8aa27SPeixin-Qiao  call t%t3%t2%t1(1:)%info2
116c6d8aa27SPeixin-Qiao  !ERROR: Reference to rank-2 object 't1' has 1 subscripts
117c6d8aa27SPeixin-Qiao  call t%t3%t2%t1(1:)%g1
118c6d8aa27SPeixin-Qiao
119ddb35533SPeter Klausler  !ERROR: An allocatable or pointer component reference must be applied to a scalar base
120ddb35533SPeter Klausler  print *, t(1)%t3(1)%t2(1)%t1%p
121ddb35533SPeter Klausler  !ERROR: An allocatable or pointer component reference must be applied to a scalar base
122ddb35533SPeter Klausler  print *, t%t3(1)%t2(1)%t1(1,1)%p
123ddb35533SPeter Klausler  !ERROR: An allocatable or pointer component reference must be applied to a scalar base
124ddb35533SPeter Klausler  print *, t(1)%t3(1)%t2(1)%t1%a
125ddb35533SPeter Klausler  !ERROR: An allocatable or pointer component reference must be applied to a scalar base
126ddb35533SPeter Klausler  print *, t%t3(1)%t2(1)%t1(1,1)%a
127ddb35533SPeter Klausler  !ERROR: An allocatable or pointer component reference must be applied to a scalar base
128ddb35533SPeter Klausler  t(1)%t3(1)%t2(1)%t1%p => null()
129ddb35533SPeter Klausler  !ERROR: An allocatable or pointer component reference must be applied to a scalar base
130ddb35533SPeter Klausler  t%t3(1)%t2(1)%t1(1,1)%p => null()
131ddb35533SPeter Klausler
13248a70ea1SPeixin-Qiaoend
133