Skip to content

Commit 84851cd

Browse files
committed
initial commit
1 parent f9d0ef9 commit 84851cd

File tree

2 files changed

+96
-3
lines changed

2 files changed

+96
-3
lines changed

flang/lib/Evaluate/intrinsics.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ ENUM_CLASS(KindCode, none, defaultIntegerKind,
111111
atomicIntKind, // atomic_int_kind from iso_fortran_env
112112
atomicIntOrLogicalKind, // atomic_int_kind or atomic_logical_kind
113113
sameAtom, // same type and kind as atom
114+
ExtensibleOrUnlimitedType, // extensible or unlimited polymorphic type
114115
)
115116

116117
struct TypePattern {
@@ -160,7 +161,8 @@ static constexpr TypePattern AnyChar{CharType, KindCode::any};
160161
static constexpr TypePattern AnyLogical{LogicalType, KindCode::any};
161162
static constexpr TypePattern AnyRelatable{RelatableType, KindCode::any};
162163
static constexpr TypePattern AnyIntrinsic{IntrinsicType, KindCode::any};
163-
static constexpr TypePattern ExtensibleDerived{DerivedType, KindCode::any};
164+
static constexpr TypePattern ExtensibleDerived{
165+
DerivedType, KindCode::ExtensibleOrUnlimitedType};
164166
static constexpr TypePattern AnyData{AnyType, KindCode::any};
165167

166168
// Type is irrelevant, but not BOZ (for PRESENT(), OPTIONAL(), &c.)
@@ -2103,9 +2105,18 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
21032105
}
21042106
return std::nullopt;
21052107
} else if (!d.typePattern.categorySet.test(type->category())) {
2108+
std::string expectedText;
2109+
switch (d.typePattern.kindCode) {
2110+
case KindCode::ExtensibleOrUnlimitedType:
2111+
expectedText = "extensible derived or unlimited polymorphic type";
2112+
break;
2113+
default:
2114+
break;
2115+
}
21062116
messages.Say(arg->sourceLocation(),
2107-
"Actual argument for '%s=' has bad type '%s'"_err_en_US, d.keyword,
2108-
type->AsFortran());
2117+
"Actual argument for '%s=' has bad type '%s'%s"_err_en_US, d.keyword,
2118+
type->AsFortran(),
2119+
expectedText.empty() ? "" : ", expected " + expectedText);
21092120
return std::nullopt; // argument has invalid type category
21102121
}
21112122
bool argOk{false};
@@ -2244,6 +2255,17 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
22442255
return std::nullopt;
22452256
}
22462257
break;
2258+
case KindCode::ExtensibleOrUnlimitedType:
2259+
argOk = type->IsUnlimitedPolymorphic() ||
2260+
(type->category() == TypeCategory::Derived &&
2261+
IsExtensibleType(GetDerivedTypeSpec(type)));
2262+
if (!argOk) {
2263+
messages.Say(arg->sourceLocation(),
2264+
"Actual argument for '%s=' has bad type '%s', expected extensible derived or unlimited polymorphic type"_err_en_US,
2265+
d.keyword, type->AsFortran());
2266+
return std::nullopt;
2267+
}
2268+
break;
22472269
default:
22482270
CRASH_NO_CASE;
22492271
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
! RUN: %python %S/test_errors.py %s %flang_fc1
2+
3+
module m
4+
type :: t1
5+
real :: x
6+
end type
7+
type :: t2(k)
8+
integer, kind :: k
9+
real(kind=k) :: x
10+
end type
11+
type :: t3
12+
real :: x
13+
end type
14+
type, extends(t1) :: t4
15+
integer :: y
16+
end type
17+
type :: t5
18+
sequence
19+
integer :: x
20+
integer :: y
21+
end type
22+
23+
24+
integer :: i
25+
real :: r
26+
type(t1) :: x1, y1
27+
type(t2(4)) :: x24, y24
28+
type(t2(8)) :: x28
29+
type(t3) :: x3
30+
type(t4) :: x4
31+
type(t5) :: x5
32+
class(t1), allocatable :: a1
33+
class(t3), allocatable :: a3
34+
35+
36+
logical :: t1_1 = same_type_as(x1, x1)
37+
logical :: t1_2 = same_type_as(x1, y1)
38+
logical :: t1_3 = same_type_as(x24, x24)
39+
logical :: t1_4 = same_type_as(x24, y24)
40+
logical :: t1_5 = same_type_as(x24, x28) ! ignores parameter
41+
logical :: t1_6 = .not. same_type_as(x1, x3)
42+
logical :: t1_7 = .not. same_type_as(a1, a3)
43+
!ERROR: Actual argument for 'a=' has bad type 't5', expected extensible derived or unlimited polymorphic type
44+
logical :: t1_8 = same_type_as(x5, x5)
45+
!ERROR: Actual argument for 'a=' has bad type 't5', expected extensible derived or unlimited polymorphic type
46+
logical :: t1_9 = same_type_as(x5, x1)
47+
!ERROR: Actual argument for 'b=' has bad type 't5', expected extensible derived or unlimited polymorphic type
48+
logical :: t1_10 = same_type_as(x1, x5)
49+
!ERROR: Actual argument for 'a=' has bad type 'INTEGER(4)', expected extensible derived or unlimited polymorphic type
50+
logical :: t1_11 = same_type_as(i, i)
51+
!ERROR: Actual argument for 'a=' has bad type 'REAL(4)', expected extensible derived or unlimited polymorphic type
52+
logical :: t1_12 = same_type_as(r, r)
53+
!ERROR: Actual argument for 'a=' has bad type 'INTEGER(4)', expected extensible derived or unlimited polymorphic type
54+
logical :: t1_13 = same_type_as(i, t)
55+
56+
logical :: t2_1 = extends_type_of(x1, y1)
57+
logical :: t2_2 = extends_type_of(x24, x24)
58+
logical :: t2_3 = extends_type_of(x24, y24)
59+
logical :: t2_4 = extends_type_of(x24, x28) ! ignores parameter
60+
logical :: t2_5 = .not. extends_type_of(x1, x3)
61+
logical :: t2_6 = .not. extends_type_of(a1, a3)
62+
logical :: t2_7 = .not. extends_type_of(x1, x4)
63+
logical :: t2_8 = extends_type_of(x4, x1)
64+
!ERROR: Actual argument for 'a=' has bad type 't5', expected extensible derived or unlimited polymorphic type
65+
logical :: t2_9 = extends_type_of(x5, x5)
66+
!ERROR: Actual argument for 'a=' has bad type 't5', expected extensible derived or unlimited polymorphic type
67+
logical :: t2_10 = extends_type_of(x5, x1)
68+
!ERROR: Actual argument for 'mold=' has bad type 't5', expected extensible derived or unlimited polymorphic type
69+
logical :: t2_11 = extends_type_of(x1, x5)
70+
end module
71+

0 commit comments

Comments
 (0)