File: io15.f90

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (55 lines) | stat: -rw-r--r-- 1,594 bytes parent folder | download | duplicates (14)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
! RUN: %python %S/test_errors.py %s %flang_fc1
! Test visibility restrictions
module m
  type t1
    integer, private :: ip1 = 123
   contains
    procedure :: fwrite1
    generic :: write(formatted) => fwrite1
  end type t1
  type t2
    integer, private :: ip2 = 234
    type(t1) x1
  end type t2
  type t3
    type(t1) x1
    type(t2) x2
  end type t3
  type, extends(t2) :: t4
  end type t4
 contains
  subroutine fwrite1(x, unit, iotype, vlist, iostat, iomsg)
    class(t1), intent(in) :: x
    integer, intent(in) :: unit
    character(*), intent(in) :: iotype
    integer, intent(in) :: vlist(:)
    integer, intent(out) :: iostat
    character(*), intent(in out) :: iomsg
    write(unit, *, iostat=iostat, iomsg=iomsg) '(', iotype, ':', vlist, ':', x%ip1, ')'
  end subroutine
  subroutine local ! all OK since type is local
    type(t1) :: x1
    type(t2) :: x2
    type(t3) :: x3
    type(t4) :: x4
    print *, x1
    print *, x2
    print *, x3
    print *, x4
  end subroutine
end module

program main
  use m
  type(t1) :: x1
  type(t2) :: x2
  type(t3) :: x3
  type(t4) :: x4
  print *, x1 ! ok
  !ERROR: I/O of the derived type 't2' may not be performed without defined I/O in a scope in which a direct component like 'ip2' is inaccessible
  print *, x2
  !ERROR: I/O of the derived type 't3' may not be performed without defined I/O in a scope in which a direct component like 'ip2' is inaccessible
  print *, x3
  !ERROR: I/O of the derived type 't4' may not be performed without defined I/O in a scope in which a direct component like 'ip2' is inaccessible
  print *, x4
end