Skip to content

Commit e6feea5

Browse files
committed
simplify error string creation
1 parent cf1d47f commit e6feea5

File tree

2 files changed

+15
-20
lines changed

2 files changed

+15
-20
lines changed

flang/lib/Evaluate/intrinsics.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2105,18 +2105,13 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
21052105
}
21062106
return std::nullopt;
21072107
} 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-
}
2108+
const char *expected{
2109+
d.typePattern.kindCode == KindCode::extensibleOrUnlimitedType
2110+
? ", expected extensible or unlimited polymorphic type"
2111+
: ""};
21162112
messages.Say(arg->sourceLocation(),
21172113
"Actual argument for '%s=' has bad type '%s'%s"_err_en_US, d.keyword,
2118-
type->AsFortran(),
2119-
expectedText.empty() ? "" : ", expected " + expectedText);
2114+
type->AsFortran(), expected);
21202115
return std::nullopt; // argument has invalid type category
21212116
}
21222117
bool argOk{false};
@@ -2261,7 +2256,7 @@ std::optional<SpecificCall> IntrinsicInterface::Match(
22612256
IsExtensibleType(GetDerivedTypeSpec(type)));
22622257
if (!argOk) {
22632258
messages.Say(arg->sourceLocation(),
2264-
"Actual argument for '%s=' has type '%s', but was expected to be an extensible derived or unlimited polymorphic type"_err_en_US,
2259+
"Actual argument for '%s=' has type '%s', but was expected to be an extensible or unlimited polymorphic type"_err_en_US,
22652260
d.keyword, type->AsFortran());
22662261
return std::nullopt;
22672262
}

flang/test/Semantics/dynamic-type-intrinsics.f90

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ module m
4040
integer(kind=merge(kind(1),-1,same_type_as(x1, x3))) same_type_as_x1_x3_false
4141
!ERROR: INTEGER(KIND=-1) is not a supported type
4242
integer(kind=merge(kind(1),-1,same_type_as(a1, a3))) same_type_as_a1_a3_false
43-
!ERROR: Actual argument for 'a=' has type 't5', but was expected to be an extensible derived or unlimited polymorphic type
43+
!ERROR: Actual argument for 'a=' has type 't5', but was expected to be an extensible or unlimited polymorphic type
4444
logical :: t1_8 = same_type_as(x5, x5)
45-
!ERROR: Actual argument for 'a=' has type 't5', but was expected to be an extensible derived or unlimited polymorphic type
45+
!ERROR: Actual argument for 'a=' has type 't5', but was expected to be an extensible or unlimited polymorphic type
4646
logical :: t1_9 = same_type_as(x5, x1)
47-
!ERROR: Actual argument for 'b=' has type 't5', but was expected to be an extensible derived or unlimited polymorphic type
47+
!ERROR: Actual argument for 'b=' has type 't5', but was expected to be an extensible or unlimited polymorphic type
4848
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
49+
!ERROR: Actual argument for 'a=' has bad type 'INTEGER(4)', expected extensible or unlimited polymorphic type
5050
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
51+
!ERROR: Actual argument for 'a=' has bad type 'REAL(4)', expected extensible or unlimited polymorphic type
5252
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
53+
!ERROR: Actual argument for 'a=' has bad type 'INTEGER(4)', expected extensible or unlimited polymorphic type
5454
logical :: t1_13 = same_type_as(i, t)
5555

5656
integer(kind=merge(kind(1),-1,extends_type_of(x1, y1))) extends_type_of_x1_y1_true
@@ -64,10 +64,10 @@ module m
6464
!ERROR: INTEGER(KIND=-1) is not a supported type
6565
integer(kind=merge(kind(1),-1,extends_type_of(x1, x4))) extends_type_of_x1_x4_false
6666
integer(kind=merge(kind(1),-1,extends_type_of(x4, x1))) extends_type_of_x4_x1_true
67-
!ERROR: Actual argument for 'a=' has type 't5', but was expected to be an extensible derived or unlimited polymorphic type
67+
!ERROR: Actual argument for 'a=' has type 't5', but was expected to be an extensible or unlimited polymorphic type
6868
logical :: t2_9 = extends_type_of(x5, x5)
69-
!ERROR: Actual argument for 'a=' has type 't5', but was expected to be an extensible derived or unlimited polymorphic type
69+
!ERROR: Actual argument for 'a=' has type 't5', but was expected to be an extensible or unlimited polymorphic type
7070
logical :: t2_10 = extends_type_of(x5, x1)
71-
!ERROR: Actual argument for 'mold=' has type 't5', but was expected to be an extensible derived or unlimited polymorphic type
71+
!ERROR: Actual argument for 'mold=' has type 't5', but was expected to be an extensible or unlimited polymorphic type
7272
logical :: t2_11 = extends_type_of(x1, x5)
7373
end module

0 commit comments

Comments
 (0)