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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
! RUN: %flang -verify -fsyntax-only < %s
! RUN: %flang -fsyntax-only -verify -ast-print %s 2>&1 | %file_check %s
function swap(p)
type ipoint
sequence
integer x,y
end type
type(ipoint) swap, p
swap%x = p%y
swap%y = p%x
end
PROGRAM typetest
INTEGER Bar ! expected-note {{previous definition is here}}
TYPE Point
REAL X, Y ! expected-note {{passing argument to field 'x' declared here}}
END TYPE Point ! expected-note@-1 {{passing argument to field 'y' declared here}}
type Triangle
type(Point) vertices(3)
end type
TYPE foo
INTEGER K
END TYPE bar ! expected-error {{expected type name 'foo'}}
type Bar ! expected-error {{redefinition of 'bar'}}
real x
endtype
type person
integer age ! expected-note {{previous declaration is here}}
real age ! expected-error {{duplicate member 'age'}}
endtype
type seq
sequence
type(Point) p1 ! expected-error {{member 'p1' requires a type with a 'sequence' attribute ('type point' invalid)}}
integer x
end type
type ipoint
sequence
integer x, y
end type
type(Point) p
type(Triangle) tri
integer i
character c
type(ipoint) ip
type(zzzzz) zvar ! expected-error {{use of undeclared identifier 'zzzzz'}}
type(Bar) barvar ! expected-error {{invalid type name 'bar'}}
p = Point(1.0, 2.0)
p = Point(0,1) ! CHECK: point(real(0), real(1))
p = i ! expected-error {{assigning to 'type point' from incompatible type 'integer'}}
i = p ! expected-error {{assigning to 'integer' from incompatible type 'type point'}}
tri = p ! expected-error {{assigning to 'type triangle' from incompatible type 'type point'}}
p = Point(.true., p) ! expected-error {{passing 'logical' to parameter of incompatible type 'real'}}
continue ! expected-error@-1 {{passing 'type point' to parameter of incompatible type 'real'}}
p = Point(0.0) ! expected-error {{too few arguments to type constructor, expected 2, have 1}}
p = Point(0.0, 1.0, 2.0) ! expected-error {{too many arguments to type constructor, expected 2, have 3}}
p = Point() ! expected-error {{too few arguments to type constructor, expected 2, have 0}}
i = p%x + p%y
p%x = 1.0
p%y = p%x
tri%vertices(1) = p
p = tri%vertices(1)
tri%vertices = Point(0,0)
i = p%z ! expected-error {{no member named 'z' in 'type point'}}
c = p%x ! expected-error {{assigning to 'character' from incompatible type 'real'}}
ip = swap(ipoint(1,2))
p = swap(ipoint(1,2)) ! expected-error {{assigning to 'type point' from incompatible type 'type ipoint'}}
END PROGRAM typetest
function func(p)
type Point
real x,y
end type
type(Point) func, p
func = Point(p%y, p%x)
end
|