File tree Expand file tree Collapse file tree 2 files changed +81
-1
lines changed Expand file tree Collapse file tree 2 files changed +81
-1
lines changed Original file line number Diff line number Diff line change @@ -2695,9 +2695,16 @@ void ArraySpecVisitor::PostAttrSpec() {
2695
2695
2696
2696
FuncResultStack::~FuncResultStack () { CHECK (stack_.empty ()); }
2697
2697
2698
+ // True when either type is absent, or if they are both present and are
2699
+ // equivalent for interface compatibility purposes.
2698
2700
static bool TypesMismatchIfNonNull (
2699
2701
const DeclTypeSpec *type1, const DeclTypeSpec *type2) {
2700
- return type1 && type2 && *type1 != *type2;
2702
+ if (auto t1{evaluate::DynamicType::From (type1)}) {
2703
+ if (auto t2{evaluate::DynamicType::From (type2)}) {
2704
+ return !t1->IsEquivalentTo (*t2);
2705
+ }
2706
+ }
2707
+ return false ;
2701
2708
}
2702
2709
2703
2710
void FuncResultStack::CompleteFunctionResultType () {
Original file line number Diff line number Diff line change
1
+ ! RUN: %python %S/test_errors.py %s %flang_fc1 -Werror
2
+ ! Catch discrepancies between implicit result types and a global definition,
3
+ ! allowing for derived types and type equivalence.
4
+
5
+ module m
6
+ type t1
7
+ integer n
8
+ end type
9
+ type t2
10
+ real a
11
+ end type
12
+ type t3
13
+ sequence
14
+ integer n
15
+ end type
16
+ end
17
+
18
+ function xfunc1 ()
19
+ use m
20
+ type (t1) xfunc1
21
+ xfunc1% n = 123
22
+ end
23
+
24
+ function yfunc1 ()
25
+ use m
26
+ type (t1) yfunc1
27
+ yfunc1% n = 123
28
+ end
29
+
30
+ function zfunc1 ()
31
+ type t3
32
+ sequence
33
+ integer n
34
+ end type
35
+ type (t3) zfunc1
36
+ zfunc1% n = 123
37
+ end
38
+
39
+ program main
40
+ use m
41
+ implicit type (t1) (x)
42
+ implicit type (t2) (y)
43
+ implicit type (t3) (z)
44
+ print * , xfunc1() ! ok
45
+ print * , xfunc2() ! ok
46
+ ! ERROR: Implicit declaration of function 'yfunc1' has a different result type than in previous declaration
47
+ print * , yfunc1()
48
+ print * , yfunc2()
49
+ print * , zfunc1() ! ok
50
+ print * , zfunc2() ! ok
51
+ end
52
+
53
+ function xfunc2 ()
54
+ use m
55
+ type (t1) xfunc2
56
+ xfunc2% n = 123
57
+ end
58
+
59
+ function yfunc2 ()
60
+ use m
61
+ ! ERROR: Function 'yfunc2' has a result type that differs from the implicit type it obtained in a previous reference
62
+ type (t1) yfunc2
63
+ yfunc2% n = 123
64
+ end
65
+
66
+ function zfunc2 ()
67
+ type t3
68
+ sequence
69
+ integer n
70
+ end type
71
+ type (t3) zfunc2
72
+ zfunc2% n = 123
73
+ end
You can’t perform that action at this time.
0 commit comments